Re: qw with strings containing spaces
Mathew Snyder wrote: I need to populate a select multiple on a web page when it loads with a series of values. Most of the values will be determined dynamically when the code runs but some are static. They look like A - H, I - P and Q - Z. The spaces are for readability. What I am doing is declaring an array and assigning the value: @array = qw/All A - H I - P Q - Z/; and then pushing the to-be-determined values onto the array later on. However, when I print this all out while testing, I get each letter, hyphen and quote as individual elements. I've tried escaping different ways to no avail. I've looked on PerlMonks and saw a solution which created a scalar with a string containing each item separated by commas. It is then run through the split() function using the commas as the delimiter. I'd like a more succinct and cleaner method of doing this though, if possible. Any ideas? Mathew Why not just declare @array like this: my @array = (All, A - H, I - P, Q - Z); and then later push new variables onto it, like so: push @array, qw/1 2 3/; -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4011.25 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How do I create this string?
John W. Krahn wrote: Flemming Greve Skovengaard wrote: Travis Thornhill wrote: I need to make strings of variable length for testing inputs. The strings can contain any letter, say 'a', and I need to be able to create the string with 255, 256 or any length. Is there a quick and easy way to do this with perl? This will generate a string of random length between 1 and 256 with random letters from a to z. I have only tested it lightly, so the best of luck to you. use strict; use warnings; my ($rand_string, $index); $index should be declared inside the for loop, not at file scope. Yes, my mistake. my @letters = qw( a b c d e f g h i j k l m n o p q r s t u v w x y z ); Could be shortened to: my @letters = 'a' .. 'z'; I knew there was a way to do with the range operator, but I kept drawing a blank. my $length = int rand( 255+1 ); Why not just rand( 256 )? I meant to write: int rand( 256+1 ) That would produce a number between 1..256 instead of 0..255. Or at least it should according to how I understand rand() to work. for (1..$length) { $index = int rand(scalar @letters-1); You have an off-by-one error. The letter 'z' will never be picked. Yes, I see that now. But I did write lightly tested. $rand_string .= $letters[$index]; Or simply: $rand_string .= $letters[ rand @letters ]; Yes, that would save a line of code, a variable and a call to scalar(). But shouldn't that be: $rand_string .= $letters[ int rand @letters ]; instead? } print $rand_string, \n; You could write that on one line as: my $rand_string = join '', map $letters[ rand @letters ], 1 .. $length; Ahh, the oneliner. Something that almost always takes me longer to make than a small multiline script. John -- Flemming Greve Skovengaard The figure stands expressionless a.k.a Greven, TuxPower Impassive and alone [EMAIL PROTECTED] Unmoved by this victory 4011.25 BogoMIPSAnd the seeds of death he's sown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How do I create this string?
Travis Thornhill wrote: I need to make strings of variable length for testing inputs. The strings can contain any letter, say 'a', and I need to be able to create the string with 255, 256 or any length. Is there a quick and easy way to do this with perl? ... This will generate a string of random length between 1 and 256 with random letters from a to z. I have only tested it lightly, so the best of luck to you. use strict; use warnings; my ($rand_string, $index); my @letters = qw( a b c d e f g h i j k l m n o p q r s t u v w x y z ); my $length = int rand( 255+1 ); for (1..$length) { $index = int rand(scalar @letters-1); $rand_string .= $letters[$index]; } print $rand_string, \n; -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerThe world is doomed to die [EMAIL PROTECTED] Fire in the sky 4011.25 BogoMIPS The end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Time::Local let me faint
Practical Perl wrote: Hello,lists, Please see these two lines' output: [$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,8,2006)' Day '31' out of range 1..30 at -e line 1 $ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,7,2006)' 1156953600 I translate the time of '2006-7-31 00:00:00' to unix timestamp,it's successful. But when I translate the time of '2006-8-31 00:00:00' to unix timestamp,it said '31 out of range'. I'm so faint that August doesn't have 31th day?Please tell me why this happen and how to resolve it. Thank you very much. I believe it is because the months are 0-indexed (0-11), so timelocal(0,0,0,31,8,2006) is 2006-7-31 *not* 2006-8-31. It also say so in the documentation. perldoc Time::Local Hope it helps. -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4011.74 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex to match a range of numbers
Joshua Colson wrote: On Thu, 2006-06-08 at 00:55 +0200, Flemming Greve Skovengaard wrote: If you are just going to print the day number and you have other dates in a similar format why not just use: print +(split /\s+/, $date)[2]; Well, in this particular instance, I am. However, there have been at least a few times in the past that I've wanted to achieve the same thing and it always ends up looking like comic book curse words. Also, I prefer to validate the input. This example would match even if the third column weren't digits (more specifically, digits in the range of 1 to 31). Thanks. OK, how about this. This however does not check whether the month can have 31 days. #!/usr/bin/perl use strict; use warnings; my @dates = ( Wed Jun 7 14:27:38 2006, Wed Jun 47 14:27:38 2006, ); foreach my $date ( @dates ) { my $day_number = ( split /\s+/, $date )[2]; if ( $day_number =~ m/ ^(?: [12]?[1-9] | # 1-9, 11-19, 21-29 or [1-3]0 | # 10,20,30 or 31 # 31 )$ /x ) { print $day_number, \n; # Or whatever you want to do with the day number } } -- Flemming Greve Skovengaard Just a few small tears between a.k.a Greven, TuxPower Someone happy and one sad [EMAIL PROTECTED] Just a thin line drawn between 4181.33 BogoMIPS Being a genius or insane -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex to match a range of numbers
Joshua Colson wrote: I'm trying to parse a date from a file and I would like to know how to match a range of numbers with a regex? For example, the days of the month 1..31. I understand that there are numerous modules that can do the work for me, this is as much for my own learning as anything. Thanks. --- #!/usr/bin/perl use strict; use warnings; my $date = Wed Jun 7 14:27:38 2006'; print $3 if $date =~ m{(Wed)\s(Jun)\s{1,2}([1..31])}; __END__ If you are just going to print the day number and you have other dates in a similar format why not just use: print +(split /\s+/, $date)[2]; -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4181.33 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Date difference.
Brian Volk wrote: Excellent summary of most methods at http://perlmeme.org/faqs/datetime/comparing_dates.html. Regards James Turnbull Hi All, I'm running through the example of Date::Calc on the site listed above. When I plug in today's date as my birthday... it returns: I am -31 days old. I would have guessed 0 days old. Can someone pls explain this to me? (localtime)[5,4,3] stands for [$year, $mon, $mday] correct? #!/usr/bin/perl use strict; use warnings; use Date::Calc qw(Delta_Days); my @today = (localtime)[5,4,3]; $today[0] += 1900; my @birthday = (2006, 4, 6); my $days = Delta_Days(@birthday, @today); print I am $days days old\n; exit 0; Thank you! perldoc -f localtime localtime EXPR Converts a time as returned by the time function to a 9-element list with the time analyzed for the local time zone. Typically used as follows: # 012 3 45 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); All list elements are numeric, and come straight out of the C `struct tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the speci- fied time. $mday is the day of the month, and $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December. $year is the number of years since 1900. That is, $year is 123 in year 2023. $wday is the day of the week, with 0 indicating Sunday and 3 indicat- ing Wednesday. $yday is the day of the year, in the range 0..364 (or 0..365 in leap years.) $isdst is true if the specified time occurs during daylight savings time, false otherwise. Hope it helps. -- Flemming Greve Skovengaard Man still has one belief, a.k.a Greven, TuxPower One decree that stands alone [EMAIL PROTECTED]The laying down of arms 4181.44 BogoMIPS Is like cancer to their bones -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: A Strange Syntax
Wiggins d'Anconia wrote: Now that you understand it, replace it with $sym-{name} so the next person doesn't have to ask. Unless you are using a really old Perl. Actually that should be *sym-{name} instead of $sym-{name} ( or %sym-{name} but that's deprecated ). Else you get Variable $sym is not imported at ... when using 'use strict;' ( as you should ). -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerThe world is doomed to die [EMAIL PROTECTED] Fire in the sky 4112.38 BogoMIPS The end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex puzzle
bingfeng zhao wrote: See following sample code: CODE use warnings; use strict; my @address = (http://test;, http://;, www, , ftp:/foo ); for (@address) { print \$_\ passed! \n if /^((http|ftp):\/\/)?.+$/; } /CODE the running result is: http://test; is valid. http://; is valid. www is valid. ftp:/foo is valid. why http://; and ftp:/foo can pass the check? Because ((http|ftp):\/\/) is optional ( the ? following it does that ), so any line with anything between the start and end of the line will pass. -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Internal server error
vishwas bhakit wrote: hello I am running cgi script from browser n getting Internal server error. When i checked logs it is giving following error: BEGIN failed--compilation aborted at /path/to/file/file.cgi line 4. what may be the cause of this can you plz help me. Thnx in advance Yahoo! India Matrimony: Find your life partneronline. Post your code if you want help, most of us don't have psychic powers :) -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4112.38 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: LWP get_tag('img')
Brian Volk wrote: Hi All, I'm having trouble narrow down the correct img tag... This piece of code will get ALL the img tags: while (my $img_tag = $parser-get_tag('img')) { my $i = $img_tag-[1]; my $code = $i-{'src'}; print $code\n } All I want is the 11th one... so I tried to do a foreach (1..11) , very unsucessful... :~) Any suggestions would be greatly appreciated Here is the whole script __begin__ #!/usr/bin/perl use strict; use warnings; use HTML::TokeParser::Simple; use LWP::Simple; my $url = http://www.rcpworksmarter.com/rcp/products/detail.jsp?rcpNum=1013 http://www.rcpworksmarter.com/rcp/products/detail.jsp?rcpNum=1013 ; my $page = get($url) or die Could not load URL\n; my $parser = HTML::TokeParser::Simple-new(\$page) or die Could not parse page; while (my $img_tag = $parser-get_tag('img')) { my $i = $img_tag-[1]; # attributes of this img tag my $code = $i-{'src'}; print $code\n; } __end__ Thanks! Brian Volk HP Products 317.298.9950 x1245 mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] A quick solution could be: my $counter = 0; while (my $img_tag = $parser-get_tag('img')) { ++$counter; my $i = $img_tag-[1]; # attributes of this img tag my $code = $i-{'src'}; if($counter == 11) { print $code\n; last; } } But there is properly a better solution. -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: problem printf
deny wrote: Try to add this lines somewhere the top of the file: use strict; use warnings; and report the errors, if any. Global symbol $md5 requires explicit package name at ./checksum.pl line 11. Global symbol @dirs requires explicit package name at ./checksum.pl line 12. Global symbol $dir requires explicit package name at ./checksum.pl line 14. Good, now you're on the right track. Declare those variables ( with my ) and read the reply by John W. Krahn. -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerA tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS The end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reading from a filehandle in while-loop
Bastian Angerstein wrote: Why does this dont work in my Script? open (TEST, /tmp/test.txt); while (TEST) { print $_; # or just print; } Does the file exists and can you read it? -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4112.38 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reading from a filehandle in while-loop
Bastian Angerstein wrote: Joop, if I use open... or die $! i see that the file is opened correctly but nothing is in $_. -Ursprngliche Nachricht- Von: Flemming Greve Skovengaard [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 26. Oktober 2004 11:45 An: [EMAIL PROTECTED] Cc: Bastian Angerstein Betreff: Re: Reading from a filehandle in while-loop Bastian Angerstein wrote: Why does this dont work in my Script? open (TEST, /tmp/test.txt); while (TEST) { print $_; # or just print; } Does the file exists and can you read it? Bottompost, please. Your script works on my machine. Is this you whole script, do you use: use strict; use warnings; in your script and is there any content in /tmp/test.txt? -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4112.38 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reading from a filehandle in while-loop
Bastian Angerstein wrote: I noticed that while ($test=TEST) works on my system perfectly but while (TEST) dont ... dont know why... should reinstall perl. Thanks for your help Bastian They should both work, why they don't is beyond me. Please post on the list, I am *not* a all-seeing, all-knowing Perl guru, you know, while I can't answer why one work and the other doesn't someone else on the list might. And again, please bottompost. -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: problem printf
deny wrote: That isn't only perl code, it's incomplete, and it doesn't use 'printf'. Show us more code and explain your problem fully. thanks for your help here is the complete code #!/usr/bin/perl use MD5; require 'find.pl'; $md5 = new MD5; @dirs = @ARGV; foreach $dir ( @dirs ) { find($dir); } sub wanted { push @files, $name; } foreach $name ( sort @files) { ($uid,$gid) = (stat $nane)[4,5]; $stat = sprintf %0o, (stat_)[2]; unless( -f $name ) { printf $stat\t$uid $gid\t\t\t\t\t\t$name\n; next; } $md5-reset(); open FILE, $name or print(STDERR can't open file $name\n), next; $md5-addfile(FILE); close FILE; $checksum - $md5-hexdigest(); printf $stat\t$uid $gid $checksum\t$name\n; } it aim to calcute sum permission on the dir in @ARGV; and with diff ,you can see if files was modified but the result isnt fine as you can see below [EMAIL PROTECTED] cgi-bin]$ ./checksum.pl /bin 0 /bin 0 /bin/arch 0 /bin/awk 0 /bin/basename 0 /bin/bash 0 /bin/bash2 0 /bin/cat 0 /bin/chgrp 0 /bin/chmod thanks Try to add this lines somewhere the top of the file: use strict; use warnings; and report the errors, if any. -- Flemming Greve Skovengaard Just a few small tears between a.k.a Greven, TuxPower Someone happy and one sad [EMAIL PROTECTED] Just a thin line drawn between 4112.38 BogoMIPS Being a genius or insane -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to empty the buffer
[EMAIL PROTECTED] wrote: Hi I have written a program to add the strings. Now after every execution how to flush out the out. how $i = 0; while(LOGFILE) { $i++; if ($i 10) { last; } $var = $_; $msg2=$var\n; } print $msg2; After this I want to empty the $msg2. How? Regards Sreedhar $msg2 = ; -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerA tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS The end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need Help
Anish Kumar K. wrote: Hi Please anyone help me in Reg Exp. I wanted to replace [%one_two%] and [%pne%] with the value New say... I wrote the following code...I am unable to get the output as This is a test for New number and New numbers. I am getting it as This a test for New numbers. WHICH IS WRONG... Please let me know what to do If I need to replace in both... Thanks Anish #!/usr/bin/perl $openTag='\[%'; $closeTag='%\]'; my $count=0; $_= This is a test for [%one_two%] number and [%pne%] numbers.; s/$openTag.*$closeTag/New/g; print The new line is:: $_ \n; .* is greedy and will match from the first $openTag til the last $closeTag, from here -[%one_two%] number and [%pne%]- to here. Use .*? instead, it is non-greedy and will match from here -[%one_two%]- to here and from here -[%pne%]- to here. I can recommed Mastering Regular Expressions form O'Reilly if you want to learn more. -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerThe world is doomed to die [EMAIL PROTECTED] Fire in the sky 4112.38 BogoMIPS The end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to access first key of Hash of Hash
Edward Wijaya wrote: On 29 Sep 2004 14:58:00 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote: If I understood this correctly, you want to do this: So sorry for being not clear. I will extend just a bit. Suppose I have: my %HoH = ( firstkey = { A = 'blabla', B = 'dadada', C = 'tititi',} secondkey = { D = 'blabla', E = 'dadada', F = 'tititi',} ); and I generated that HoH with this: $HoH{$fkey}{$alpha}=$text; namely: firstkey, secondkey from $fkey A, B, C, etcfrom $alpha blabla etc from $text my question is how can I print output like: firstkey secondkey How about: print $_\n foreach( keys( %HoH ) ); or map{ print $_\n } keys( %HoH ); Remember that a hash stores its keys/values in random order, so you will get your keys in random order. given the construction variables as mention before. -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerA tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS The end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: qx{} and ping problem.
Gary Stainburn wrote: Hi folks. Got the simplest of small scripts that runs ping and shows the summary. However, although the ping command works at the shell, it doesn't work in the perl script. any ideas? #!/usr/bin/perl -w while(1) { my @lines=qx{ping -n 50 10.1.1.31}; my $times=pop @lines; my $counts=pop @lines; print $times $counts; if ($times=~/^(\d+) .?, (\d+) .?, (\d+%)/) { $sent=$1; $rec=$2; $perc=$3; printf %3d %3d %3d %s, $sent,$rec,$perc,$times; } sleep 60; } #--- lswitchh.ringways.co.uk ping statistics --- #120 packets transmitted, 120 packets received, 0% packet loss #round-trip min/avg/max/mdev = 0.243/0.391/0.834/0.079 ms [EMAIL PROTECTED] gary]$ ping lswitchh # [EMAIL PROTECTED] gary]$ ./pingcheck connect: Invalid argument Use of uninitialized value in concatenation (.) at ./pingcheck line 7. Use of uninitialized value in concatenation (.) at ./pingcheck line 7. Use of uninitialized value in pattern match (m//) at ./pingcheck line 8. ^C [EMAIL PROTECTED] gary]$ Don't you mean 'ping -n -c 50 10.1.1.31' instead of 'ping -n 50 10.1.1.31'. Else read the man page for ping. -- Flemming Greve Skovengaard Man still has one belief, a.k.a Greven, TuxPower One decree that stands alone [EMAIL PROTECTED]The laying down of arms 4112.38 BogoMIPS Is like cancer to their bones -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Using reference or throw valuables to sub ?
Bee wrote: Say I have an array that carries at least 2mb data or 70mb max, but in my code, I want to throw this array to another sub ( within the same package )for further operations . so, which one I would better to use and what's the reason ? gosub [EMAIL PROTECTED] or gosub @array Is that if I throw the array to another sub also means the array would be copied and then pass to the target sub ? Yes while reference is using the same data in system memory? Yes Thanks -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: A regex problem.
Denham Eva wrote: Hello Gurus, In a script I have a piece of code as such:- * snip** my $filedate =~ s/(\d+)//g; Try this instead: my $filedate; if( $var_with_file_name =~ m/(\d+)\.csv$/ ) { $filedate = $1; } print $filename\n; * snip end *** The data I am parsing looks as such :- ** DATA C:/directory/MSISExport_20040814.csv C:/directory/MSISExport_20040813.csv . . . . C:/directory/MSISExport_20030501.csv ** DATA end * Now I am actually trying to dump everything except the date or numerals as such :- 20040814 Can someone help me with that regex? I am having a frustrating time of it! Much appreciated Denham -- Flemming Greve Skovengaard Man still has one belief, a.k.a Greven, TuxPower One decree that stands alone [EMAIL PROTECTED]The laying down of arms 4112.38 BogoMIPS Is like cancer to their bones -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: date format
[EMAIL PROTECTED] wrote: All, I have this code: my ($month, $day, $year) = (localtime)[4,3,5]; printf (%02d/%02d/%02d\n, $month+1,$day,$year+1900); which gives me 08/16/2004 what I want is 08/16/04. Should I just use Posix with strftime or is there a quicker way w/out having to load the Posix module? also, why I ntoiced I had to may $month+1 otherwise it outputs a month back. why is this? thanks, derek printf (%02d/%02d/%02d\n, $month + 1, $day, $year - 100); # Only works when $year 1999. Try 'perldoc -f localtime' to learn why this works. -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: date format
Bob Showalter wrote: Flemming Greve Skovengaard wrote: printf (%02d/%02d/%02d\n, $month + 1, $day, $year - 100); # Only works when $year 1999. And when $year = 2099 :~) Stick to $year % 100; Yes, you are correct. Your solution is fool proof. -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: date format
[EMAIL PROTECTED] wrote: I have this value, from the date format solution emails, in a subroutine and I want to pass it to a if clause, how would I go about this? Can I assign a literal such as sub datemanip { my ( $month, $day, $year) = (localtime)[4,3,5]; my $foodate = printf (%02d/%02d/%02d\n, $month + 1, $day, ($year %100)); Use sprintf for that. I use sprintf in one of my programs like this: my $d8_dato = sprintf( %4d%02d%02d, ( substr( $dato, 4, 4 ), substr( $dato, 2, 2 ), substr( $dato, 0, 2 ) ) ); } while (D) if ( $_ =~ $foodate) { It would work, if you use sprintf as shown above. But I would write: if ( $_ =~ m/$foodate/ ) instead to eliminate confusesing when maintaining the code later. . } -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
GD make test fails
I am having problems with GD-2.16 and I have been Google'ing for a while now without finding anything that applies to my problem. I have solved the first hurdle I had with undefined symbol: libiconv. Seems that libiconv should be compiled with '--without-libiconv-prefix' or else gdlib-config --libs reports /usr/lib/libiconv.so instead of -liconv. Now I don't get the same errors, but when I run 'make test TEST_VERBOSE=1' I get: PERL_DL_NONLAZY=1 /usr/bin/perl -MExtUtils::Command::MM -e test_harness(1, 'blib/lib', 'blib/arch') t/*.t t/GD..1..10 ok 1 not ok 2 not ok 3 not ok 4 not ok 5 not ok 6 not ok 7 ok 8 # Skip, FreeType changes too frequently to be testable not ok 9 not ok 10 FAILED tests 2-7, 9-10 Failed 8/10 tests, 20.00% okay (less 1 skipped test: 1 okay, 10.00%) t/Polyline1..1 # Running under perl version 5.008004 for linux # Current time local: Thu Aug 12 00:19:31 2004 # Current time GMT: Wed Aug 11 22:19:31 2004 # Using Test.pm version 1.24 ok 1 ok Failed Test Stat Wstat Total Fail Failed List of Failed --- t/GD.t108 80.00% 2-7 9-10 1 subtest skipped. Is this serious enough to make GD not work? BTW, I am using: Slackware 9.1 with kernel 2.6.7 Perl 5.8.4 and I have all the prerequisites for building GD from source. -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl Core
James Edward Gray II wrote: On Jul 31, 2004, at 11:30 AM, Randy W. Sims wrote: On 7/31/2004 12:24 PM, James Edward Gray II wrote: Quick question: What's the best way to find out if a module is standard in the Perl Core and if it is, when it was added? Check out Module::CoreList http://search.cpan.org/dist/Module-CoreList/ perl -MModule::CoreList -e1 Can't locate Module/CoreList.pm in @INC (@INC contains: /System/Library/Perl/5.8.1/darwin-thread-multi-2level /System/Library/Perl/5.8.1 /Library/Perl/5.8.1/darwin-thread-multi-2level /Library/Perl/5.8.1 /Library/Perl /Network/Library/Perl/5.8.1/darwin-thread-multi-2level /Network/Library/Perl/5.8.1 /Network/Library/Perl .). BEGIN failed--compilation aborted. Guess that leads me to the question, when was Module::CoreList added? James Module::CoreList is *not* a core module. I think what Randy W. Sims meant by check out is download and install. -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowera tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS the end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: howto 'cat file|grep foo bar|wc -l' in perl
Maurice Lucas wrote: Hello, I just started using perl and want to rewrite a simple bash script i've been using in the past to perl. I want to cat file|grep foo bar|wc -l and tried it the following way which worked for foobar as one word and not as two words. --- #!/usr/bin/perl $logfile = /var/log/logfile; $grep_cmd = /bin/grep; $string = $ARGV[0]; $count = 0; open(LOG, cat $logfile|$grep_cmd $string|) || die Ooops; while($line = LOG) { $count++; } print $count\n; --- I would write like this: #!/usr/bin/perl use strict;# Always use strict use warnings; # Very helpful, especially if you are new to Perl die No argument\n if ( @ARGV == 0 ); my $logfile = /var/log/logfile; my $string = $ARGV[0]; my $count = 0; # Open a file like this open( LOG, $logfile ) or die Cannot open '$logfile': $!\n; while( LOG ) { my $line = $_;# $_ contains the current line of LOG ++$count if ( $line =~ m/$string/ ); } print $count\n; calling this program with ./count.pl foobar works and with Yes, foobar is one argument. ./count.pl foo bar doesn't works neither does No, because 'foo bar' is two arguments, arguments is separated by spaces. ./count.pl foo bar works Yes, foo bar is one argument. How do I write this the right way? My way works, 'cause I'm always right :) No seriously TIMTOWTDI. With kind regards Met vriendelijke groet, Maurice Lucas TAOS-IT -- Flemming Greve Skovengaard Man still has one belief, a.k.a Greven, TuxPower One decree that stands alone [EMAIL PROTECTED]The laying down of arms 4112.38 BogoMIPS Is like cancer to their bones -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: setting the environment variables in perl
Paul Kraus wrote: You can access all the env variables like this... $ENV{ 'VAR' } example my $home = $ENV{ 'HOME' }; print $home\n; I have never tried to change them but I would assume that it would work. HTH, Paul Kraus On Tue, Jul 27, 2004 at 07:29:45AM -0700, jason corbett wrote: How does one go about assuring that the environment variables are properly set in perl? I read several books, but none go in depth about how to write a script that includes all the required variables, that way nothing gets left out. Please advise. JC [snipet] #!/usr/bin/perl -w $ENV{ORACLE_HOME}=/orav101/oracle/8.1.7; use strict; use DBI; use lib '/home/samcsm/jason/myperl/lib/perl5/site_perl/'; Use this one-liner to check your environment variables: perl -Mstrict -we 'foreach my $key (sort keys %ENV) { print $key = $ENV{$key}\n }' -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerthe world is doomed to die [EMAIL PROTECTED] fire in the sky 4112.38 BogoMIPS the end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reading a PDF file using PERL in UNIX
Jaffer Shaik wrote: Dear Friends, My OS is unix. Using perl, I want to read a pdf file and print its contents. How can I achieve this using perl. Regards, Jaffer. http://search.cpan.org/ Search for PDF -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowera tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS the end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Returning variables from sub routines.
jason corbett wrote: I have a sub routine that I created called dateme. when i run the sub routine, I am getting errors that Global symbol $process_date requires explicit package name at What gives? Thanks, JC Here is the snipet #---called from dateme( ); #--- sub dateme{ my $process_date=' '; $process_date=localtime( ); return $process_date; } There is no problem in this sample code. But somewhere else in your program you must use $process_date without declaring it first. -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4112.38 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Dot not string cat?
Bryan Harris wrote: Does anyone know why this doesn't do what I expect? % perl -e '$i=123.52.32.1; $j=45; $b=$i_.$j*2; print $b, \n;' 90 I'd like it to print: 123.52.32.1_90 What's going on here? TIA. - Bryan Yoy don't have a variable called $i_. Changed '$b=$i_.$j*2;' to '$b=${i}_.$j*2;' -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowera tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS the end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: (repost) how can i generate 10 unique (non repeating) numbers
Absolut Newbie wrote: Hi, (reposting this since i did not see the original in my newsreader or google) I want to generate 10 numbers from 1..15 and put them in an array. easy ? while ($fill 10){ $foo = int(rand(15)); unshift(@array, $foo); $fill++; } print the [EMAIL PROTECTED] is -- @array\n; my problem is that many times the numbers repeat themselves in the array. the @array is -- 5 10 8 3 0 13 14 9 0 10 how can i generate 10 unique (non repeating) numbers from a range to put in the array ? thanx. --- Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.719 / Virus Database: 475 - Release Date: 7/18/2004 Be patient when posting. This will generate numbers between 1 and 15. foreach (1..10) { my $bar = int(rand(15)) + 1; # Since you want numbers 1..15 not 0..14 unshift(@array, $bar); } Since rand uses the internal clock (correct me if I am wrong) you're bound to get repeated numbers. If you only want non-repeating numbers, run through the array and only unshift if the number is not in the array already. -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowera tale of death and doom [EMAIL PROTECTED] Odin saw the final sign 4112.38 BogoMIPS the end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: question about strict
FyD wrote: Dear All, I have two perl scripts: - The first one: sub Tt { $TTT = uc($TTT); if(($TTT ne ON) ($TTT ne OFF)){ print ERROR: Check variable TTT;} else { print It is a Test...;} } # ---MAIN--- $TTT = OFF; Tt(); If I use $TTT = OFF, I get 'It is a Test...' and if I use $TTT=O I get 'ERROR: Check variable TTT'. This, it is normal for me. - The second script using 'strict' this time: use strict; sub Tt { my $TTT; $TTT = uc($TTT); if(($TTT ne ON) ($TTT ne OFF)){ print ERROR: Check variable TTT;} else { print It is a Test...;} } # ---MAIN--- my $TTT = OFF; Tt(); If I use $TTT = OFF I get time 'ERROR: Check variable TTT', Why ? Thanks, Francois Because $TTT is undef. When you declare $TTT i Tt perl creates a new variable and hides away the $TTT from the main part of your script to be restored when Tt returns. Change 'my $TTT;' in Tt to my '$TTT = shift;' and call Tt like this 'Tt($TTT)'. You should *always* use, use strict;. -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4112.38 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using tr
Ricardo SIGNES wrote: * Cinzia Sala [EMAIL PROTECTED] [2004-07-07T09:35:42] I would like to transform a string like : MSDDIDWLHSRRGVCK in a identical string, but with two spaces between each letter: You wouldn't use tr/// for this. There are two simple ways: $string =~ s/(.)(?!\Z)/$1 /g; # replace any char /not/ followed by end-of-string with itself and a # space or $string = join(' ', split('', $string)); # split $string into individual characters # then rejoin them with two spaces between them consult perldoc -f split and perldoc -f join for the latter one. or $string =~ s/(?!^)(?=[a-z])/ /gi; # Insert two spaces where the next character is a letter (case insensitive) # and the previous is *not* start of string -- Flemming Greve SkovengaardThe prophecy of the holy Norns a.k.a Greven, TuxPowerthe world is doomed to die [EMAIL PROTECTED] fire in the sky 4112.38 BogoMIPS the end is coming soon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how does this work
Lino Iozzo wrote: where would i do that...what does that mean? I am using windows 2000 and unix. Lino [snip] OK, we'll take it step by step. FOR UNIX: cd to where your placed the archive, then run tar -zxvf module_name.tar.gz (for information about the tar flags see the man page for tar), then cd module_name make make test make install FOR WINDOWS: You're on your own :) -- Flemming Greve Skovengaard Just a few small tears between a.k.a Greven, TuxPower Someone happy and one sad [EMAIL PROTECTED] Just a thin line drawn between 4168.08 BogoMIPS Being a genius or insane -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how does this work
Lino Iozzo wrote: my apologies for beating this to death and i do appreciate your help...i have never had to do this. but i am making an effort to learn what is the man page? Manual page, try typing 'man tar'. this is what i downloaded: stable.tar.gz then there was also this: MD5; do you know the difference? stable.tar.gz.MD5 contains a MD5 checksum to verify that stable.tar.gz is not corrupt. To check if stable.tar.gz is corrpt type 'md5sum -c stable.tar.gz.MD5', this should output 'stable.tar.gz: OK' if the file is OK. you said: tar -zxvf module_name.tar.gz would i type: tar -zxvf stable.tar.gz and run this? Yes. thanks for the help... Lino [snip] Also for Windows the is something called ActiveState Perl http://www.activestate.com/Products/ActivePerl/ however I have never installed myself (I have never used Windows of my own free will for the past 3 years). -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4168.08 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Getting into programming with perl.
Leke Lapinkangas wrote: Hi, Can anyone recommend books which might be useful to somebody who has never programmed in any language before? Though something linked in with perl would be an advantage. Thanks, Leke Hi. I can highly recommend 'Learning Perl 3rd Edition' from O'Reilly. It is easy to understand, very well written and covers all the basic Perl, so it should get you started. -- Flemming Greve Skovengaard Be it the Devil or be it him a.k.a Greven, TuxPower You can count on just one thing [EMAIL PROTECTED] When the time is up, you'll know 4168.08 BogoMIPS Not just one power runs the show -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: directory operations
MuthuKumar wrote: Hello All, I have a directory which contains several files.. like .txt .html .js files like that. I have to search a pattern in all files.. if it is available then replace it and else leave it out. I have made it for single file.. what i want is to implement for the full directory.. my @file_list = /*.txt/ foreach $file (@file_list){ file loop snip. close(file-handle); } I have checked like this.. i did not get any response at all.. No files are stored in the array too. what is wrong with this.. and how to accomplish this. -- Regards, Muthukumar. You need to change the line: my @file_list = /*.txt/ to my @file_list = *.txt or my @file_list = glob *.txt -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4168.08 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: string change problem
MuthuKumar wrote: Hai all. I want to make a script which converts like (pErl1234test = perl).I wrote like #!/usr/bin/perl print Enter ur name $name = STDIN $org_name = $name $name =~ s/\W.*//; #change 1 $name =~ tr/A-Z/a-z/; #change 2 print Old = $org_name\n; print New = $name\n; But i can not get a change on the change 1 and 2 lines. Regards, Muthukumar. This should work: __BEGIN__ #!/usr/bin/perl my ($name, $org_name); print Enter your name: ; chomp($name = STDIN); $org_name = $name; $name =~ s/[^A-Za-z]\w*//g; #change 1 $name =~ tr/A-Z/a-z/; #change 2 print Old = $org_name\n; print New = $name\n; __END__ -- Flemming Greve SkovengaardAnd when you kill a man, you're a murderer a.k.a Greven, TuxPowerKill many, and you're a conqueror [EMAIL PROTECTED] Kill them all ... Ooh ... Oh you're a god! 4168.08 BogoMIPS - MegaDeth, Countdown to Extinction -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sort function?
Use this: __BEGIN__ use strict; use warnings; die No file name supplied.\n unless @ARGV; my $oldest_name = shift @ARGV; my $oldest_age = -C $oldest_name; foreach (@ARGV) { my $age = -C; ($oldest_name, $oldest_age) = ($_, $age) if ($age $oldest_age); } printf The oldest file is '%s', and it is %.1f days old.\n, $oldest_name, $oldest_age; __END__ This is a modified version of the solution to exercise 11-3 in Learning Perl (which I assume you are reading). The unmodified version uses '-M' not '-C'. Radhika Sambamurti wrote: Hi, I have written a small script that is supposed to tell me the oldest file in my directory (as per ctime). I have read the various times the various files were created, into an array called times. I have then sorted this array - @sorted_times. when i do ls -l i get the following: wxrwxr-x 1 radhika wheel 1028 Mar 24 11:57 chapter11_1.pl -rwxrwxr-x 1 radhika wheel 387 Mar 24 12:37 chapter11_2.pl -rwxrwxr-x 1 radhika wheel 551 Mar 24 21:25 chapter11_3.pl -rwxrwxr-x 1 radhika wheel 281 Mar 15 16:28 file_basename.pl -rw-rw-r-- 1 radhika wheel 236 Mar 21 11:46 filereader.pl -rw-rw-r-- 1 radhika wheel 115 Mar 24 12:04 new.txt -rw-rw-r-- 1 radhika wheel 115 Mar 24 12:00 rad.txt -rwxrwxr-x 1 radhika wheel 648 Mar 15 15:40 rm_file_30days.pl -rwxrwxr-x 1 radhika wheel 554 Mar 15 16:37 rmoldshares.pl and when I execute the program I get the following: radhika$ ./chapter11_3.pl * Mon Mar 15 15:55:58 2004 Mon Mar 15 16:28:50 2004 Mon Mar 15 16:37:46 2004 Sun Mar 21 11:46:36 2004 Wed Mar 24 11:57:21 2004 Wed Mar 24 12:00:15 2004 Wed Mar 24 12:04:01 2004 Wed Mar 24 12:37:10 2004 Wed Mar 24 21:26:56 2004 my question is - where did the very first line from my output come from? ie Mon Mar 15 15:55:58. As you can see, ls -l does not show any file created at that time. Even . and .. are not the above time. Is it using sort(@array), that sorts it in some manner that I do not understand? Thanks, Radhika -- I've pasted the code for the script below. #! /usr/bin/perl -w use strict; use diagnostics; my $create_time; my $i=0; my @times; my @sorted_times; my $file; foreach $file (@ARGV) { my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($file); $create_time = localtime($ctime); $times[$i] = $create_time; $i++; } @sorted_times = sort(@times); my $this_time; foreach $this_time (@sorted_times) { my($day, $mon, $dt, $tm, $yr) = split /\s+/,$this_time; my ($hr, $mn, $sec) = split /:/, $tm; print $this_time\n; } -- Flemming Greve Skovengaard Be it the Devil or be it him a.k.a Greven, TuxPower You can count on just one thing [EMAIL PROTECTED] When the time is up, you'll know 4168.08 BogoMIPS Not just one power runs the show -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problem recording the first digits into a scalar
This should give you what you need: my $digit = 0; foreach (@commands) { /^\d+/; print FILE DIGIT = $\n; } Hemond, Steve wrote: Hi ppl, I have to split a file in pieces and I place every segment in an array. Each segment begins with digit(s). What I want to do is to parse the array, and for each segement, record its first digits into a scalar so I can do further manipulations on it (actually I only print the scalar into a file). What I do right now is : my $digit = 0; for (@commands) { $digit =~ /^\d+/; print FILE DIGIT = $digit \n; } The resulting file displays : 0 0 0 0 0 0 ... etc. Here are some sample segments : 1NP256ES-0 -- here it should take 1 61PC61 -- here it should take 61 1LT -- here it should take 1 16PC16 -- here it should take 16 I am missing something for sure ... but what? Any clues? Thank you so much in advance, Best regards, Steve Hemond Programmeur Analyste / Analyst Programmer Smurfit-Stone, Ressources Forestieres La Tuque, P.Q. Tel.: (819) 676-8100 X2833 [EMAIL PROTECTED] -- Flemming Greve SkovengaardAnd when you kill a man, you're a murderer a.k.a Greven, TuxPowerKill many, and you're a conqueror [EMAIL PROTECTED] Kill them all ... Ooh ... Oh you're a god! 4168.08 BogoMIPS - MegaDeth, Countdown to Extinction -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problem recording the first digits into a scalar
Yes, your code is more readable and fail safe. Also I was not aware of the performance penalty in using $, so thanks for teaching me something too. I am still learning Perl. Wiggins d Anconia wrote: This should give you what you need: my $digit = 0; foreach (@commands) { /^\d+/; print FILE DIGIT = $\n; } While simple, use of $ takes a performance penalty and a readability penalty From perldoc perlvar: The use of this variable anywhere in a program imposes a considerable performance penalty on all regular expression matches. See the BUGS manpage. http://danconia.org [snip] -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the fortune, the pain, [EMAIL PROTECTED] Go to war again, blood is freedom's stain, 4168.08 BogoMIPS Don't you pray for my soul anymore. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response