415 Posted Topics
Re: Consider using Tie::File. [QUOTE]Tie::File represents a regular text file as a Perl array. Each element in the array corresponds to a record in the file. The first line of the file is element 0 of the array; the second line is element 1, and so on. The file is not … | |
Re: [QUOTE=terabyte;1620213]I've been programming a web crawler for a while, I'm almost done, it works perfectly but when it crawls vbulletin forums i get weird urls example: forum/index.php?phpsessid=oed7fqnm9ikhqq9jvbt23lo8e4 index.php/topic,5583.0.html?phpsessid=93f6a28f192c8cc8b035688cf8b5e06d obviously this is being causes by php session IDs what can I do to stop this? I tried using cookies with HTTP::Cookies … | |
Re: I don't know what you mean by "there can actually be many files for each record" but I think you want an array of hash references. See [URL="http://perldoc.perl.org/perldsc.html"]http://perldoc.perl.org/perldsc.html[/URL][CODE]#!/usr/bin/perl; use strict; use warnings; use Data::Dumper; my @AoH;#Array of hash references while(my $line = <DATA>){ chomp($line); my ($id, $filename, $size) = split/\s+/, … | |
Re: [CODE]#!/usr/bin/perl; use strict; use warnings; while (<DATA>){ my @whitespacegroups = m/\w(\s+)\w/g; foreach my $whitespacegroup(@whitespacegroups){ my $count = length $whitespacegroup; print "$count spaces\t"; } print "\n"; } __DATA__ I wake up in the morning What time? Always wakeup at 6am.[/CODE]Output is: [ICODE]1 spaces 5 spaces 1 spaces 10 spaces 32 spaces … | |
Re: We need to know what delimiter character you use to separate the columns in your file. When you post the data without wrapping it in [noparse][CODE][/CODE][/noparse] tags all duplicate spaces or tabs become single spaces so we can't see some of the delimiters. If you put only one single space … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; my (@array, $foundvar1, $foundvar2); while (<DATA>){ chomp; if (m/Var1 data:/){ $foundvar1 = 1; } elsif (m/Var2 data:/){ $foundvar1 = 0; $foundvar2 = 1; } else { if ($foundvar1){ my @rec = split /,/, $_; push @{$array[0]}, join ',', @rec; } if ($foundvar2){ my @rec = … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; use File::Basename; my %hash; open my $fh, '<', '2.txt'; while (<$fh>){ chomp; my @flds = split; my $fullname = $flds[0]; my $name = fileparse($fullname,qw(.fit .vcor)); #Remove the file extension $hash{$name} = join ' ', @flds[2..$#flds]; } close $fh; open $fh, '<', '1.txt'; while (<$fh>){ chomp; … | |
Re: [QUOTE=hari kishan;1615059]Hi, This is my first post in the forum. I got a situation where i have to find a file in a folder based on its extension and there by use the file name and contents of the file. Thanks for the reply.[/QUOTE] If the extension of the files … | |
Re: Please show us an example of a negative bitstring. I think that since you say "big-endian" you have generated your bitstring according to the 2's Complement method but I'm not sure about that. [URL="http://simple.wikipedia.org/wiki/Negative_binary_numbers"][QUOTE]There are two methods for storing negative binary numbers, they are Sign and Magnitude and 2's Complement.[/QUOTE][/URL] | |
Re: If you want to save the results of a query in a table have a look at [URL="http://dev.mysql.com/doc/refman/5.1/en/create-table-select.html"]create table select[/URL]. | |
Re: The [URL="http://perldoc.perl.org/Tie/File.html"]Tie::File[/URL] module lets you treat a file like an array so you can repeatedly loop through it and push new records into it.[CODE]#!/usr/bin/perl #tie_file.pl; use strict; use warnings; use Tie::File; my $filename = '/home/david/Programming/data/new1.txt'; tie my @array, 'Tie::File', $filename or die "Unable to Tie $filename: $!"; my ($input, $input1); … | |
Re: I don't have your kind of database and am not familiar with awk so I don't understand your script. To create an output file whose name is the current date you can do the following:[CODE]#!/usr/bin/perl use strict; use warnings; my ($day, $month, $year) = (localtime)[3,4,5]; my $filename = sprintf("%04d-%02d-%02d\n", $year+1900, … | |
Re: Try creating a table having the same column names whose columns are all VARCHAR and import your data into that. That should work as long as your VARCHAR columns are big enough. Then you can write a query that reads the data from this all-VARCHAR table and INSERTs into the … | |
Re: I think the map name must correspond to what you refer to in usemap. In your example, [icode]usemap="#bearface"[/icode] but [icode]<map name="bear">[/icode] | |
Re: [QUOTE=senthilamp4;1567588]Dear Experts, Here i am written code for convert the text to CSV file conversion. i am facing a problem in while compare the two array to print the values row wise. below i have mentioned my code,input and output format. input : "OC192-11,OC192:CVS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:ESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:SESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:SEFSS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:CVL,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:ESL,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:SESL,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" … ![]() | |
Re: Current Turn Around Time does not belong in your table. Make it a calculated column in the query that selects from your table. The following shows an item that came in 12 days ago and hasn't gone out yet so date_out is NULL. [CODE]CREATE TABLE IF NOT EXISTS `test`( `id` … | |
Re: [QUOTE]Undefined subroutine &main::start called at getwords.pl line 27.[/QUOTE] The error message says it can't find your [ICODE]start[/ICODE] function. It doesn't mention a function named 'parse', you need to define a function or subroutine named 'start' in your main package. For example, if you have an html file in your current … | |
Re: If you don't test whether each of your open statements succeeded by adding [iCODE]or die $![/iCODE] you won't know which one of them fails. See the simple examples at the beginning of [URL="http://perldoc.perl.org/functions/open.html"]perldoc -f open[/URL]. Also every script should [ICODE]use strict; use warnings;[/ICODE] | |
Re: [QUOTE=Diwakar Gana;1581363]Dear All, Can anybody tell me how to autoincrement the Hexa decimal value. For Ex: I am having the value FF0B in Result array and want increment it to FF0C. Now Result array should contain two values.[/QUOTE](I assume you mean 'increment' because I think 'autoincrement' refers to database table … | |
Re: You have declared $baz with the [ICODE]my[/ICODE] function which limits the scope of $baz to the block in which it is declared thus making it impossible to obtain its value from outside that block. [URL="http://perldoc.perl.org/perlmod.html"]A my declares the listed variables to be local (lexically) to the enclosing block[/URL]... In the … | |
Re: [iCODE]<form name="login" action="$cgidir?action=verify_login" method="POST">[/iCODE] The above doesn't look right to me. To get it to work I put it in an html document like the following:[CODE=html]<html> <header> <title>Post form example</title> </header> <body> <form name="login" action="/cgi-bin/verify_login" method="POST"> <input type="text" name="user"> <input type="password" name="pass"> <input type="submit" name="login" value="Login"> </form> </body> </html>[/CODE]Then your … | |
Re: [QUOTE=bio-grad;1573911]sample data was copied and pasted - in gedit there are tabs between columns, but here it appears as spaces.[/QUOTE] If you click the "Manage Attachments" button you can attach your input file so that it preserves all the data correctly. You may need to add an acceptable file extension … | |
Re: You are opening a file without testing if the open was successful. Add an 'or die..' and error message to your open statement so you will know if your open statement failed and have some clue why it didn't work. Also, you are assuming your file contains only one line … | |
Re: Nobody who hasn't already died can know for sure what it's like, so I can't really fear death -- only my idea of what death might be like. Most of the time I don't fear my idea of death nearly so much as I fear some of the events or … | |
![]() | Re: Rather than struggle to compose one regex that does all the substitution I would use two regexes. I find it easier to understand and change if necessary.[CODE]#!/usr/bin/perl use strict; use warnings; my @words = qw(iodine Thiodi number dix Iodic iodide); foreach my $word(@words){ $word =~ s/(?<!io)di/deu/i;#Replace di with deu unless … ![]() |
Re: Looks like your loop is calling alarm multiple times. [URL="http://perldoc.perl.org/functions/alarm.html"]Only one timer may be counting at once. Each call disables the previous timer...[/URL] | |
Re: Remove the following line from inside your foreach loop and put it before the beginning of the loop starts. [iCODE]open OUTFILE, ">$file" or die "unable to open $file $!";[/iCODE] Opening a file for output multiple times results in overwriting the existing file each time so that only the last thing … | |
Re: I haven't used fork and don't know much about it, but doesn't a return value of 0 mean this is a child process? So why does your script [iCODE]print "parent\n";[/iCODE] when the $pid == 0? How about using an environmental variable to pass each array element to a child, so … | |
Re: The semicolon is optional for the last statement in a block of Perl statements. I think that explains your seeing a one-liner ending in a print command not terminated with a semicolon. | |
Re: You need to show us more than one line of code. Also "application/xml; charset=UTF-8" doesn't look like an error message to me. The utf8 module allows you to use accented characters as values or variable names in your script source code, but that's all it does, so maybe you need … | |
Re: I bought and read [URL="http://www.perl.org/books/beginning-perl/"]Beginning Perl by Simon Cozens[/URL] and have since downloaded it and reread much of it so that's the one I would recommend. You can [URL="http://www.perl.org/books/beginning-perl/"]download it for free[/URL] now. | |
Re: [QUOTE=bioinfo90;1565029]i NEED A PERL SCRIPT TO CREATE NAME_DIRECTORY FOR ALL TRAJECTORIES. i've trajectory files like this, rep2.tra3M.bz2 rep2.tra4M.bz2 rep2.tra5M.bz2 rep2.tra6M.bz2 rep2.tra7M.bz2 i want a scipt to list all replicas,copy zipped replicas and unzip all replicas and create a file with list of replicas and call make_pdb.pl for all trajectories.[/QUOTE] What … | |
Re: I would start by writing a query that gives the information needed for the report. Print the results of the query. Call it a report.:) If the report required must have a specific layout such as headers, details, subtotals, groups, footers, page numbers, etc. then you'll need to look for … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; print "ESS\tSESS\tSEFSS\tCVL\n"; while(<DATA>){ s/"//g;#Remove all double quotes my @fields = m/(.+?,)/g; print chr(34), @fields[0..2], chr(34), "\t"; } __DATA__ "OC192-11,OC192:ESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:SESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:SEFSS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:CVL,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"[/CODE]Running the above prints the following to STDOUT[CODE=text]ESS SESS SEFSS CVL "OC192-11,OC192:ESS,0," "OC192-11,OC192:SESS,0," "OC192-11,OC192:SEFSS,0," "OC192-11,OC192:CVL,0," [/CODE] | |
Re: Please attach data from your rep.tra1 file to your post so somebody can test your script. In what way does the output of your script not meet your expectations? | |
Re: One way of finding the first Saturday of each month for a given year:[CODE]#!/usr/bin/perl use strict; use warnings; use 5.010; use Date::Simple; my $year = 2011; my @month_names = qw(January February March April May June July August September October November December); foreach('01'..'12'){ my $dt = first_saturday($_); my $mth = $month_names[$_ … | |
Re: Another way, if you don't mind using a module:[CODE]#!/usr/bin/perl use strict; use warnings; use File::Basename; my $string ="datafiles/source/main_data_files/content.csv"; my $filename = fileparse($string); print "\nThe file name is $filename\n";[/CODE] | |
Re: What happens when you type [iCODE]c:/xampp/htdocs/test.php?emp=$id [/iCODE] into the URL area of your browser? I bet your browser can't read that as a valid URL. Your browser needs a valid URL that looks like [iCODE]http://HOSTNAME/test.php?emp=$id[/iCODE] where you replace HOSTNAME with the real host name (try [iCODE]http://localhost/test.php?emp=$id[/iCODE]). | |
Re: [QUOTE=extemer;1554049]hi guys i want to set password to mysql database please help me out[/QUOTE] For which user do you want to set a password. If you haven't created any user accounts yet I guess you mean you want to set a password for the root user. What platform does your … ![]() | |
Re: [QUOTE=tcollins412;1542257]what if thats not the only cookie?[/QUOTE] If the name of the cookie you created is 'sessionid' you can read the value of the cookie into a variable as follows:[CODE]use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); #Create a new CGI object my $cgi = new CGI; my $value=$cgi->cookie('sessionid');[/CODE]If no cookie … | |
Re: [QUOTE=Tango2010;1538358]Hi, I am attempting to read in a CSV file, modify certain arrays and output it into a new file. It works fine on a mac, however on Windows it does not do anything. Any ideas what im doing wrong? Code posted below; [CODE] open(FILE,"file.csv") or die $!; open(TARGET,"> newfile.csv") … | |
Re: [CODE]mysql> select curdate(); +------------+ | curdate() | +------------+ | 2011-05-01 | +------------+ 1 row in set (0.00 sec) mysql> select MONTH(CURDATE()); +------------------+ | MONTH(CURDATE()) | +------------------+ | 5 | +------------------+ 1 row in set (0.00 sec) [/CODE] | |
Re: Why can't you use modules? [URL="http://www.perlmonks.org/?node_id=693828"]Yes, even you can use CPAN[/URL] | |
Re: I don't know about threads and my perl is not built for threads but I can illustrate the problem by the following: [CODE]#!/usr/bin/perl use strict; use warnings; use 5.010; #When you follow the sub name with arguments in parentheses #the sub runs first and returns a scalar value, #which the … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; use constant {SECONDS_IN_DAY => 86400}; use HTTP::Date qw(time2str str2time parse_date); my $today_YMD = epoch2YMD(time); my $today_epoch = str2time($today_YMD); my $today_minus_3_epoch = $today_epoch - 3 * SECONDS_IN_DAY; my $today_minus_3_YMD = epoch2YMD($today_minus_3_epoch); my (@completed, @not_completed); my $filename = 'omar.txt'; open my $fh, '<', $filename or die "Failed … | |
Re: [QUOTE=terabyte;1542689]what is this variable: [CODE]$/[/CODE][/QUOTE] "The input record separator, newline by default. This influences Perl's idea of what a 'line' is." from [URL="http://perldoc.perl.org/perlvar.html"]http://perldoc.perl.org/perlvar.html[/URL] | |
Re: [QUOTE=debasishgang7;1522063]its not working ....[/QUOTE] If you wanted to retrieve the highest score you would use offset of 0 (not 1). And so to retrieve the 6th highest score you need an offset of 5.[CODE]SELECT id FROM members ORDER BY score desc LIMIT 5, 1;[/CODE]In English I think the above says … | |
Re: The input record separator (see [URL="http://perldoc.perl.org/perlvar.html"]perlvar[/URL]) determines how much input to read for each input record. It is newline by default. Change it to semicolon followed by newline and each time perl reads the file it will read up to the next semicolon followed by newline, which is what you … | |
Re: [QUOTE=stepamil;1517331]...I'm getting this warning message: could not find ParserDetails.ini in /usr/lib/perl5/site_perl/5.8.8/XML/SAX Is this related?[/QUOTE] Maybe not. [URL="http://perl-xml.sourceforge.net/faq/"]The Perl-XML FAQ[/URL] suggests it may have to do with how XML::SAX was installed on your computer. I don't know about this but the FAQ suggests re-installing XML::SAX and "if you are asked whether … | |
Re: I recommend installing the DBI and SQLite modules for perl and inserting your data into a database table as follows:[CODE]#!/usr/bin/perl use strict; use warnings; use DBI; # Connection to DB file created before my $dbh = DBI->connect("dbi:SQLite:dbname=demo.db","",""); $dbh->do("CREATE TABLE payments (eid,date,amount)"); my $sth = $dbh->prepare("insert into `payments` (eid,date,amount) values (?, … |
The End.