why this alarm can't work?
Hello,lists, See these code piece please: while ($cycles--) { my $c; eval { local $SIG{ALRM} = sub { die flock timeout }; alarm 3; open (SOCKLOCK,SOCK_LOCK) or die open lock file fail: $!; flock (SOCKLOCK,LOCK_EX); die can't accept unless $c = $sock-accept; flock (SOCKLOCK,LOCK_UN); close SOCKLOCK; alarm 0; }; next if $@; my $line = $c; close $c; do_real_thing($line) if $line; } In above codes,I flock a file to avoid childs competing to call the 'accept'.But since there are so many childs (my socket server accept about 200 clients' connections),so each child maybe wait somewhat long time to obtain the file-lock.So I call the 'alarm' to set a timer.After waiting for 3 seconds but the child still can't get the file-lock,it would timeout and die the 'eval'.Now the codes run normally,but I run 'strace -p 1234' (where '1234' is one of the childs' pid) under Linux shell,I see this output last out for some seconds (much more than 3 seconds): $ strace -p 28373 Process 28373 attached - interrupt to quit flock(6, LOCK_EX It seems that the 'alarm' don't get executed.Why this happen?Thanks. -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
slurp from commandline?
Hi, perl -pi.bak -e 'tr/\xA0/ /' filenames* # all files in a folder find . | xargs perl -p -i.bak -e 's/oldstring/newstring/g' perl -e 's/string/stringier/gi' -p -i.bak *.html I'm accustomed to some of those. But how do I or is it possible to file slurp on the command line, substituting \n+ with \n IOW the next code does it. But can I do this slurp/substitute directly on the commandline? How? #!/usr/bin/perl -w use strict; my $old = shift; my $new = $old.tmp; open(OLD, , $old) or die cant open $old: $!; my $text = do { local $/; OLD }; open(NEW, , $new) or die cant open $new: $!; $text =~ s/\n+/\n/g; print NEW HAL; $text HAL close(OLD) or die cant close $old: $!; close(NEW) or die cant close $new: $!; rename($old, $old.orig) or die cant rename $old to $old.orig: $!; rename($new, $old) or die cant rename $new to $old: $!; -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the problems with my CGI script
chen li schreef: my $name=$query_obj-param('text_field'); print $query_obj-p,This is your name $name, \n\n; #line31 [...] Use of uninitialized value in concatenation (.) or string at cgi_7.pl line 31. my $name = ($query_obj-param('text_field') or 'Joe?'); -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: slurp from commandline?
Alan_C wrote: Hi, Hello, perl -pi.bak -e 'tr/\xA0/ /' filenames* # all files in a folder find . | xargs perl -p -i.bak -e 's/oldstring/newstring/g' perl -e 's/string/stringier/gi' -p -i.bak *.html I'm accustomed to some of those. But how do I or is it possible to file slurp on the command line, substituting \n+ with \n It is explained in the perlrun document for the -0 (zero) switch. perldoc perlrun John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Checkbox form processing problem
Hi all, glad you seemed to like my Public Sub House routine - yes perhaps VB code ain't the best for a perl mailing list - hmmm. I got that port script working anyway, another pain in the ass job done. I was creating a checkbox form yesterday: form action=/em/admin/list_teams.pl input type=checkbox value=test1 name=team_name_0 bla1 br / input type=checkbox value=2547c17f-f831-5e0f-5351-443100357f2d name=team_name_1 checked Newcastle br / input type=checkbox value=test2 name=team_name_2 checked bla2 br / input type=hidden name=location_id value=1085 input type=hidden name=myaction value=show_teams input type=submit name=submit value=submit /form It works but unfortunately it loses the order when checking one of the checkboxes. Can anyone suggest a way to generate a checkbox form and when updating the values it keeps the order? When I say loses the order I mean, currently the order is: bla1 Newcastle bla2 updating the values the order could be: Newcastle bla1 bla2 Any sample code would be helpful. Cheers, G :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: slurp from commandline?
On Tuesday 06 June 2006 01:13, John W. Krahn wrote: [ few example commands ] I'm accustomed to some of those. But how do I or is it possible to file slurp on the command line, substituting \n+ with \n It is explained in the perlrun document for the -0 (zero) switch. perldoc perlrun Too cryptic -- IOW I'm not high enough expertise in the command line department to be able to understand/grasp from (any) of that. (I tried) I need simpler example, explanation -- that one be too high and too busy (for me, now). Next I looked perlfaq6 How can I pull out lines between two patterns that are themselves on different lines? [ snip ] If you wanted text and not lines, you would use perl -0777 -ne 'print $1\n while /START(.*?)END/gs' file1 file2 ... perl -0777 -ne 's/\n+/\n/g' rsync_sl_log.txt ^^ my 1st attempt, didn't work perl -0777 -ne 's/\n+/\n/g' while rsync_sl_log.txt ^^ 2nd attempt, didn't work ^^ perl -0777 -pne 's/\n+/\n/g' rsync_sl_log.txt ^^ 3rd -- aha!!! prints to screen with extra \n's removed!!! perl -0777 -pne 's/\n+/\n/g' rsync_sl_log.txt rsync_sl_log.txt.new ^^ 4th attempt. Bingo Works! Though I'm unsure if I'm attempting to mix shell and Perl there (bash shell redirection operator: redirect STDOUT to a file) Though it works, does anyone have any further refinement ideas? Thanks. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Checkbox form processing problem
Graeme McLaren wrote: [...] It works but unfortunately it loses the order when checking one of the checkboxes. Can anyone suggest a way to generate a checkbox form and when updating the values it keeps the order? [...] I don't know if you can ensure the browser submits elements in a certain order, but I'm certain that you can process them in the order that you desire, like so: for (sort CGI::param()) { process_whatever($_); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: slurp from commandline?
Alan_C wrote: [...] perl -0777 -pne 's/\n+/\n/g' rsync_sl_log.txt rsync_sl_log.txt.new ^^ 4th attempt. Bingo Works! Though I'm unsure if I'm attempting to mix shell and Perl there (bash shell redirection operator: redirect STDOUT to a file) Though it works, does anyone have any further refinement ideas? Thanks. It sounds like you're trying to remove blank lines. This should also do that: perl -ne '/./ print' rsync_sl_log.txt It says if there is at least a single character on the line, print the line. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
regex for date dd-mmm-yy
Hi, would anybody have to hand a regex for date dd-mmm-yy. I want to be able to validate dates that should be along the lines of : 06-jan-06 Cheers. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Checkbox form processing problem
Hey all, got it fixed all I needed was an ORDER BY id ASC clause on my SQL - sorted. G :) From: Graeme McLaren [EMAIL PROTECTED] To: beginners@perl.org Subject: Checkbox form processing problem Date: Tue, 06 Jun 2006 09:23:48 +0100 MIME-Version: 1.0 X-Originating-IP: [62.254.183.162] X-Originating-Email: [EMAIL PROTECTED] X-Sender: [EMAIL PROTECTED] Received: from lists.develooper.com ([63.251.223.186]) by bay0-mc4-f11.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 6 Jun 2006 01:25:31 -0700 Received: (qmail 14542 invoked by uid 514); 6 Jun 2006 08:24:28 - Received: (qmail 14533 invoked from network); 6 Jun 2006 08:24:27 - Received: from x1a.develooper.com (HELO x1.develooper.com) (216.52.237.111) by lists.develooper.com with SMTP; 6 Jun 2006 08:24:27 - Received: (qmail 25537 invoked by uid 225); 6 Jun 2006 08:24:27 - Received: (qmail 25533 invoked by alias); 6 Jun 2006 08:24:27 - Received: pass (x1.develooper.com: domain of [EMAIL PROTECTED] designates 64.4.56.39 as permitted sender) Received: from bay101-f29.bay101.hotmail.com (HELO hotmail.com) (64.4.56.39)by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Tue, 06 Jun 2006 01:23:59 -0700 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 6 Jun 2006 01:23:54 -0700 Received: from 64.4.56.200 by by101fd.bay101.hotmail.msn.com with HTTP;Tue, 06 Jun 2006 08:23:48 GMT X-Message-Info: LsUYwwHHNt3660MmjhEvYg2f34OAemlK+3Wz9fWrJ/U= Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm Precedence: bulk List-Post: mailto:beginners@perl.org List-Help: mailto:[EMAIL PROTECTED] List-Unsubscribe: mailto:[EMAIL PROTECTED] List-Subscribe: mailto:[EMAIL PROTECTED] List-Id: beginners.perl.org Delivered-To: mailing list beginners@perl.org Delivered-To: beginners@perl.org X-Spam-Status: No, hits=-0.7 required=8.0tests=BAYES_20,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: la.mx.develooper.com X-OriginalArrivalTime: 06 Jun 2006 08:23:54.0009 (UTC) FILETIME=[8C39E890:01C68942] Return-Path: [EMAIL PROTECTED] Hi all, glad you seemed to like my Public Sub House routine - yes perhaps VB code ain't the best for a perl mailing list - hmmm. I got that port script working anyway, another pain in the ass job done. I was creating a checkbox form yesterday: form action=/em/admin/list_teams.pl input type=checkbox value=test1 name=team_name_0 bla1 br / input type=checkbox value=2547c17f-f831-5e0f-5351-443100357f2d name=team_name_1 checked Newcastle br / input type=checkbox value=test2 name=team_name_2 checked bla2 br / input type=hidden name=location_id value=1085 input type=hidden name=myaction value=show_teams input type=submit name=submit value=submit /form It works but unfortunately it loses the order when checking one of the checkboxes. Can anyone suggest a way to generate a checkbox form and when updating the values it keeps the order? When I say loses the order I mean, currently the order is: bla1 Newcastle bla2 updating the values the order could be: Newcastle bla1 bla2 Any sample code would be helpful. Cheers, G :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Newline error
All, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); open(FL,$output_file) or die Can't open file $!\n; my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); push @list,$mounted,$percent; } %disk =(@list); delete $disk{Mounted}; foreach (sort keys %disk) { my $value = $disk{$_}; print \t $_ = $value \n; } -- 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 for date dd-mmm-yy
On Tuesday 06 June 2006 12:52, Mark Martin wrote: Hi, would anybody have to hand a regex for date dd-mmm-yy. I want to be able to validate dates that should be along the lines of : 06-jan-06 m/(0?[1-9]|[12]\d|3[01])-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov| dec)-(\d\d)/i Untested... It does allow 31st of february and similar non existing dates though. I think this is easier to test afterwards using a module to get the maxdate in each month to compare with. Good luck! -- Bjørge Solli - Office:+47 55205847 http://www.nersc.no Nansen Environmental and Remote Sensing Center - Bergen, Norway Dept.: Mohn-Sverdrup Center for Global Ocean Studies and Operational Oceanography -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: slurp from commandline?
Alan_C wrote: On Tuesday 06 June 2006 01:13, John W. Krahn wrote: [ few example commands ] I'm accustomed to some of those. But how do I or is it possible to file slurp on the command line, substituting \n+ with \n It is explained in the perlrun document for the -0 (zero) switch. perldoc perlrun Too cryptic -- IOW I'm not high enough expertise in the command line department to be able to understand/grasp from (any) of that. (I tried) I need simpler example, explanation -- that one be too high and too busy (for me, now). Next I looked perlfaq6 How can I pull out lines between two patterns that are themselves on different lines? [ snip ] If you wanted text and not lines, you would use perl -0777 -ne 'print $1\n while /START(.*?)END/gs' file1 file2 ... perl -0777 -ne 's/\n+/\n/g' rsync_sl_log.txt ^^ my 1st attempt, didn't work That is because you are using the -n switch which doesn't print by default. You need to use the -p switch instead. perl -0777 -ne 's/\n+/\n/g' while rsync_sl_log.txt ^^ 2nd attempt, didn't work ^^ Again, you need to use the -p switch instead of the -n switch. perl -0777 -pne 's/\n+/\n/g' rsync_sl_log.txt ^^ 3rd -- aha!!! prints to screen with extra \n's removed!!! perl -0777 -pne 's/\n+/\n/g' rsync_sl_log.txt rsync_sl_log.txt.new ^^ 4th attempt. Bingo Works! You need to use EITHER the -p switch OR the -n switch but not both. Though I'm unsure if I'm attempting to mix shell and Perl there (bash shell redirection operator: redirect STDOUT to a file) Though it works, does anyone have any further refinement ideas? perl -i.old -p0777e'y/\n//s' rsync_sl_log.txt perl -li.old -p00e1 rsync_sl_log.txt John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
On Jun 6, 2006, at 12:59, joseph wrote: All, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Dealing with system commands (ls, ps, df, etc.) that way is usually much tricky than it looks. Normally one goes to CPAN and checks whether someone has done it right already. In that case one installs the module and writes an easy and robust script in 5 minutes. For this particular problem delegate to Sys::Filesystem. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
joseph wrote: All, Hello, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); `df -h` does not return a file name, it returns the same output as if you had run the command 'df -h' on the command line. open(FL,$output_file) or die Can't open file $!\n; my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { There are two basic ways to do what you want: 1. for ( `df -h` ) { ... } 2. open FL, 'df -h |' or die Cannot open df pipe: $!; while ( FL ) { ... } close FL or warn $! ? Error closing df pipe: $! : Exit status $? from df; ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); You are only using two of the values so you can simplify that to: my ( $percent, $mounted ) = ( split )[ -2, -1 ]; push @list,$mounted,$percent; You don't need the array, you can assign directly to the hash: $disk{ $mounted } = $percent unless $mounted eq 'Mounted'; } %disk =(@list); delete $disk{Mounted}; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
On Tue, 2006-06-06 at 18:59 +0800, joseph wrote: All, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); $output_file =~ s/\r//g; # chomp only removes linefeed characters \n # BTW, there is no such thing as a newline; # it is either a linefeed: \n ASCII LF 0x0A # or a carriage return: \r ASCII CR 0x0D open(FL,$output_file) or die Can't open file $!\n; ... or die cannot open file '$output_file': $!\n; # print out the contents so you can see exactly what it contains. my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); push @list,$mounted,$percent; } %disk =(@list); delete $disk{Mounted}; foreach (sort keys %disk) { my $value = $disk{$_}; print \t $_ = $value \n; } -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
joseph wrote: All, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); Df can return multiple lines. I'd suspect that your string $output_file has several embedded newlines in it at this point. Chomp will only remove that last (not embedded) newline. open(FL,$output_file) or die Can't open file $!\n; my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); push @list,$mounted,$percent; You might not need the intermediate list: $disk{$mounted} = $percent; } %disk =(@list); delete $disk{Mounted}; foreach (sort keys %disk) { my $value = $disk{$_}; print \t $_ = $value \n; } I'd do it like this: use strict; use warnings; use Data::Dumper; my %disk; for (`df -h`) { next if ! m{/}; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage) = split /\s+/, $_; $disk{$mounted} = $percent; } print Dumper(\%disk); __END__ You'll notice that the backticks operator (``), in a list context, returns a list containing each line as a separate list element. Since you only seem to need two elements from the list returned by split(), you could change the two lines after the m{/} to this: my @list = split /\s+/, $_; $disk{$list[5]} = $list[4]; HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
Mr. Shawn H. Corey wrote: $output_file =~ s/\r//g; # chomp only removes linefeed characters \n # BTW, there is no such thing as a newline; # it is either a linefeed: \n ASCII LF 0x0A # or a carriage return: \r ASCII CR 0x0D \n is inherited from the C programming language and is the newline escape sequence. On Unix and Unix-like systems the newline is equivalent to the ASCII line feed character but on other systems it could be one or more different characters. http://en.wikipedia.org/wiki/Newline John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
On Jun 6, 2006, at 14:16, John W. Krahn wrote: Mr. Shawn H. Corey wrote: $output_file =~ s/\r//g; # chomp only removes linefeed characters \n # BTW, there is no such thing as a newline; # it is either a linefeed: \n ASCII LF 0x0A # or a carriage return: \r ASCII CR 0x0D \n is inherited from the C programming language and is the newline escape sequence. On Unix and Unix-like systems the newline is equivalent to the ASCII line feed character but on other systems it could be one or more different characters. To be more precise, \n in Perl is eq \012 everywhere except in Mac OS pre-X, where it is eq \015. In CRLF platforms like Win32 \n is transparently converted to CRLF on writing and back on reading by PerlIO in text mode. Thus, in a regular line-oriented script like while (my $line = FH) { # work with $line } $line ends with \n but does not contain a pair CRLF (assuming native conventions in the input). On the other direction, the string foo\n has length 4 in all systems. When you print that string into a file in text mode on Windows the bytes on disk have an extra \015, but that's transparent to the programmer. That's the point of using \n as logical/portable newline in Perl. I have written an article about newlines in Perl not yet published. All those fine details are explained there. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the problems with my CGI script
--- Dr.Ruud [EMAIL PROTECTED] wrote: chen li schreef: my $name=$query_obj-param('text_field'); print $query_obj-p,This is your name $name, \n\n; #line31 [...] Use of uninitialized value in concatenation (.) or string at cgi_7.pl line 31. my $name = ($query_obj-param('text_field') or 'Joe?'); -- Affijn, Ruud Gewoon is een tijger. Dear Dr. Ruud, Thanks it works. I change this line into: my $name = ($query_obj-param('text_field') or ' '); But I am not sure why I need to add the (or ''). I see nowhere in CGI.pm talking about it. Can you explain it in a liitle bit detail? Also what am I supposed to do if I want results not to appear on the same page as those in the form page? Thanks, Li __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 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 update my @INC (can't find .pm's after upgrading perl)
On 6/4/06, Harold Castro [EMAIL PROTECTED] wrote: I'm currently running perl-5.8.7, my modules are located in site_perl/5.8.7 however, after upgrading to 5.8.8, all of programs using perl modules, suddenly breaks because it cannot find those modules into its new supposed to be @INC (site_perl/5.8.8.. what can I do with this? I recommend you re-install the modules. Although there may be a simpler solution, this method ensures that the modules are compiled for the correct configuration of the new perl binary. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: What are the problems with my CGI script
Dear Dr. Ruud, Thanks it works. I change this line into: my $name = ($query_obj-param('text_field') or ' '); But I am not sure why I need to add the (or ''). I see nowhere in CGI.pm talking about it. Can you explain it in a liitle bit detail? Also what am I supposed to do if I want results not to appear on the same page as those in the form page? Thanks, Li or '' is a way to avoid syntax errors... cannot remember the exact error. Perl best Practices recommends using q {}; due to readability. $name = ($query_obj-param('text_field') or q {}); In a CGI program I wrote here is how I used it $q-radio_group ( -name='view', -value=[qw{All-Clients Backup-Tapes PACS-Fuji Heartlab StreamLine- Health Archiver-Status Tape-Drive-Status}], -linebreak='true', -attributes=\my %attributes), $q-defaults(-name='Default'),$q-submit('form','Send Form' ); my $which_radio_button = $q-param('view') || q{}; if ( $which_radio_button eq 'All-Clients' ) { Derek Bellner Smith Unix Systems Engineer Cardinal Health Dublin, Ohio [EMAIL PROTECTED] Cardinal Health -- Working together. For life. (sm) _ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: why this alarm can't work?
On 6/6/06, Jeff Pang [EMAIL PROTECTED] wrote: Hello,lists, See these code piece please: while ($cycles--) { my $c; eval { local $SIG{ALRM} = sub { die flock timeout }; alarm 3; open (SOCKLOCK,SOCK_LOCK) or die open lock file fail: $!; flock (SOCKLOCK,LOCK_EX); die can't accept unless $c = $sock-accept; flock (SOCKLOCK,LOCK_UN); close SOCKLOCK; alarm 0; }; next if $@; my $line = $c; close $c; do_real_thing($line) if $line; } In above codes,I flock a file to avoid childs competing to call the 'accept'.But since there are so many childs (my socket server accept about 200 clients' connections),so each child maybe wait somewhat long time to obtain the file-lock.So I call the 'alarm' to set a timer.After waiting for 3 seconds but the child still can't get the file-lock,it would timeout and die the 'eval'.Now the codes run normally,but I run 'strace -p 1234' (where '1234' is one of the childs' pid) under Linux shell,I see this output last out for some seconds (much more than 3 seconds): $ strace -p 28373 Process 28373 attached - interrupt to quit flock(6, LOCK_EX It seems that the 'alarm' don't get executed.Why this happen?Thanks. -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response You may want to use the non-blocking flock instead: my $tries; for $tries (0 .. $maxtries) { break unless flock (SOCKLOCK,LOCK_EX | LOCK_NB); } die Could not get an exclusive lock: $! if $tries == $maxtries; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Multiple Page Scrape
The script below scrapes a House of Representatives vote page which is in xml and saves it in a spreadsheet which is best opened as an xls read only. How can I: 1) scrape multiple vote pages into individual spreadsheets with a single script? 2) Only scrape columns C, F, G, H in the result here? I'd also prefer to have the spreadsheet as a csv, but that doesn't work by just changing *.xls to *.csv Thanks in advance. Ken #!/bin/perl use strict; use warnings; use WWW::Mechanize; my $output_dir = c:/training/bc; my $starting_url = http://clerk.house.gov/evs/2005/roll667.xml;; my $browser = WWW::Mechanize-new(); $browser-get( $starting_url ); foreach my $line (split(/[\n\r]+/, $browser-content)) { print $line;} open OUT, $output_dir/vote667.xls or die Can't open file:$!; foreach my $line (split(/[\n\r]+/, $browser-content)) { print OUT $line;} close OUT; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: why this alarm can't work?
On 6/6/06, Chas Owens [EMAIL PROTECTED] wrote: On 6/6/06, Jeff Pang [EMAIL PROTECTED] wrote: You may want to use the non-blocking flock instead: my $tries; for $tries (0 .. $maxtries) { break unless flock (SOCKLOCK,LOCK_EX | LOCK_NB); } die Could not get an exclusive lock: $! if $tries == $maxtries; Perl doesn't have 'break'; I think you mean 'last'. And instead of 'unless', I think you mean 'if'. But this solution is a busy wait: You're keeping the CPU busy during the retries (which is one more than $maxtries). Instead, use sleep() or the four-argument select() to let other processes use the CPU while you're waiting. As to the original problem, some systems may not support using alarm() to interrupt system calls like flock(), because (I believe) of the way that flock() is emulated. So polling, as you're suggesting, is probably the best solution in that case. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: why this alarm can't work?
On 6/6/06, Tom Phoenix [EMAIL PROTECTED] wrote: On 6/6/06, Chas Owens [EMAIL PROTECTED] wrote: On 6/6/06, Jeff Pang [EMAIL PROTECTED] wrote: You may want to use the non-blocking flock instead: my $tries; for $tries (0 .. $maxtries) { break unless flock (SOCKLOCK,LOCK_EX | LOCK_NB); } die Could not get an exclusive lock: $! if $tries == $maxtries; Perl doesn't have 'break'; I think you mean 'last'. And instead of 'unless', I think you mean 'if'. But this solution is a busy wait: You're keeping the CPU busy during the retries (which is one more than $maxtries). Instead, use sleep() or the four-argument select() to let other processes use the CPU while you're waiting. As to the original problem, some systems may not support using alarm() to interrupt system calls like flock(), because (I believe) of the way that flock() is emulated. So polling, as you're suggesting, is probably the best solution in that case. Hope this helps! --Tom Phoenix Stonehenge Perl Training Brain not work. Early morning stupor. And crap, I meant to put a sleep $wait in there. I used unless because flock returns 0 on success and -1 on failure (unless it doesn't work like C version). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: why this alarm can't work?
On 6/6/06, Chas Owens [EMAIL PROTECTED] wrote: I used unless because flock returns 0 on success and -1 on failure (unless it doesn't work like C version). Nope; it works like Perl. :-) A true value for success, false for failure. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
template loop problem
Hi all, I'm getting this error when dying out a template loop array ref: Software error: $VAR1 = [ { 'team_name' = 'bla2', 'team_id' = 'test2' }, $VAR1-[0], $VAR1-[0] ]; push @team_array, \%team; the above error is when doing die Dumper([EMAIL PROTECTED]); when I print out \%team I get : $VAR1 = { 'team_name' = 'Newcastle', 'team_id' = '2547c17f-f831-5e0f-5351-443100357f2d' }; $VAR1 = { 'team_name' = 'bla1', 'team_id' = 'test1' }; $VAR1 = { 'team_name' = 'bla2', 'team_id' = 'test2' }; When outputting to the template why doesn't the array ref contain all three of the variables above from printing out \%team ? Cheers in advance for any tips. Looks like the arrayref is being flattened but I dunno. G :) -- 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 for date dd-mmm-yy
Mark Martin schreef: would anybody have to hand a regex for date dd-mmm-yy. I want to be able to validate dates that should be along the lines of : 06-jan-06 See Regexp::Common::time (yes, lowercase 't') http://search.cpan.org/search?module=Regexp::Common::time -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: template loop problem
k got this one fixed too just needed to put a hashref inside a while loop. From: Graeme McLaren [EMAIL PROTECTED] To: beginners@perl.org Subject: template loop problem Date: Tue, 06 Jun 2006 16:06:47 +0100 MIME-Version: 1.0 X-Originating-IP: [62.254.183.162] X-Originating-Email: [EMAIL PROTECTED] X-Sender: [EMAIL PROTECTED] Received: from lists.develooper.com ([63.251.223.186]) by bay0-mc2-f3.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 6 Jun 2006 08:07:35 -0700 Received: (qmail 14559 invoked by uid 514); 6 Jun 2006 15:07:32 - Received: (qmail 14546 invoked from network); 6 Jun 2006 15:07:32 - Received: from x1a.develooper.com (HELO x1.develooper.com) (216.52.237.111) by lists.develooper.com with SMTP; 6 Jun 2006 15:07:32 - Received: (qmail 27436 invoked by uid 225); 6 Jun 2006 15:07:32 - Received: (qmail 27429 invoked by alias); 6 Jun 2006 15:07:31 - Received: pass (x1.develooper.com: domain of [EMAIL PROTECTED] designates 64.4.56.40 as permitted sender) Received: from bay101-f30.bay101.hotmail.com (HELO hotmail.com) (64.4.56.40)by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Tue, 06 Jun 2006 08:06:57 -0700 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 6 Jun 2006 08:06:51 -0700 Received: from 64.4.56.200 by by101fd.bay101.hotmail.msn.com with HTTP;Tue, 06 Jun 2006 15:06:47 GMT X-Message-Info: LsUYwwHHNt3660MmjhEvYg2f34OAemlK+3Wz9fWrJ/U= Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm Precedence: bulk List-Post: mailto:beginners@perl.org List-Help: mailto:[EMAIL PROTECTED] List-Unsubscribe: mailto:[EMAIL PROTECTED] List-Subscribe: mailto:[EMAIL PROTECTED] List-Id: beginners.perl.org Delivered-To: mailing list beginners@perl.org Delivered-To: beginners@perl.org X-Spam-Status: No, hits=-1.1 required=8.0tests=BAYES_05,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: la.mx.develooper.com X-OriginalArrivalTime: 06 Jun 2006 15:06:51.0679 (UTC) FILETIME=[D73D92F0:01C6897A] Return-Path: [EMAIL PROTECTED] Hi all, I'm getting this error when dying out a template loop array ref: Software error: $VAR1 = [ { 'team_name' = 'bla2', 'team_id' = 'test2' }, $VAR1-[0], $VAR1-[0] ]; push @team_array, \%team; the above error is when doing die Dumper([EMAIL PROTECTED]); when I print out \%team I get : $VAR1 = { 'team_name' = 'Newcastle', 'team_id' = '2547c17f-f831-5e0f-5351-443100357f2d' }; $VAR1 = { 'team_name' = 'bla1', 'team_id' = 'test1' }; $VAR1 = { 'team_name' = 'bla2', 'team_id' = 'test2' }; When outputting to the template why doesn't the array ref contain all three of the variables above from printing out \%team ? Cheers in advance for any tips. Looks like the arrayref is being flattened but I dunno. G :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Multiple Page Scrape
Since it's native xml format, I would use XML::Simple to parse it into a hash, then you can format however you want by looping through the hash. On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The script below scrapes a House of Representatives vote page which is in xml and saves it in a spreadsheet which is best opened as an xls read only. How can I: 1) scrape multiple vote pages into individual spreadsheets with a single script? 2) Only scrape columns C, F, G, H in the result here? I'd also prefer to have the spreadsheet as a csv, but that doesn't work by just changing *.xls to *.csv Thanks in advance. Ken #!/bin/perl use strict; use warnings; use WWW::Mechanize; my $output_dir = c:/training/bc; my $starting_url = http://clerk.house.gov/evs/2005/roll667.xml;; my $browser = WWW::Mechanize-new(); $browser-get( $starting_url ); foreach my $line (split(/[\n\r]+/, $browser-content)) { print $line;} open OUT, $output_dir/vote667.xls or die Can't open file:$!; foreach my $line (split(/[\n\r]+/, $browser-content)) { print OUT $line;} close OUT; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
reading Perl syntax
I'm trying to debug a failing script. It is chock full of expressions like this: $self-_read_file($self-{file}) I have never used this syntax in my own scripts which are pretty basic and getting a headache trying to figure out what that line is saying. One of the @_ array being passed to the sub `_read_file' referred to in the line above: my $file = shift; is ending up undefined so trying to track down where it gets defined. I think it is in the above line but I'm not getting what is being pointed to. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
problems with CGI and mod_perl
Hello everyone I have started since today learning how to write cgi in Perl with this doc : http://users.easystreet.com/ovid/cgi_course/lessons/lesson_one.html I am running ubuntu on my pc and I installed the package mod_perl made by ubuntu a few days ago and I was able to run Perl scripts from the Apache. I read this doc to do it : http://perl.apache.org/docs/2.0/user/intro/start_fast.html But while keeping on reading docs about Perl programming, I discovered that it is possible to install modules directly from the command line 'perl -MCPAN -e shell'. After installing some modules I didn't find in Ubuntu packages, the path to per changed from originally /usr/bin/perl to /usr/local/bin/perl . As a consequence,on my server where the perl scripts, I changed the path to the Perl interpreter from /usr/bin/perl to /usr/local/bin/perl. I have also reinstalled the Ubuntu mod_perl package but no change. Finally, each time I want to run a simple Perl script on my server, my browser asks me to download it. I don't know what to do. Thanks you very much for your help. Sami -- 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 Perl syntax
On Tue, 2006-06-06 at 12:14 -0500, [EMAIL PROTECTED] wrote: I'm trying to debug a failing script. It is chock full of expressions like this: $self-_read_file($self-{file}) I have never used this syntax in my own scripts which are pretty basic and getting a headache trying to figure out what that line is saying. One of the @_ array being passed to the sub `_read_file' referred to in the line above: my $file = shift; is ending up undefined so trying to track down where it gets defined. I think it is in the above line but I'm not getting what is being pointed to. Congratulations, you have discovered Object-Oriented Perl. For a brief introduction, read: perlbootPerl OO tutorial for beginners perltootPerl OO tutorial, part 1 perltoocPerl OO tutorial, part 2 perlbot Perl OO tricks and examples Basically, $self is a reference to a hash that has been blessed to an object. The line: $self-_read_file($self-{file}); means call the method _read_file() of the object referred to by $self using the the value of the key 'file' of the hash referred to by self. Since the method starts with an underscore, it is, by convention, considered to be an auxiliary method; which means it should only be called from other methods within the object. To see what's inside $self: use Data::Dumper; print Dumper $self; You may also want to add (before the print): $Data::Dumper::Maxdepth = 0; A Maxdepth of zero, means show the whole thing, which can be very long, so you may want to limit it to 2 or 3 so that it's easier to read. -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: problems with CGI and mod_perl
On Tue, 2006-06-06 at 19:17 +0200, sfantar wrote: Hello everyone I have started since today learning how to write cgi in Perl with this doc : http://users.easystreet.com/ovid/cgi_course/lessons/lesson_one.html I am running ubuntu on my pc and I installed the package mod_perl made by ubuntu a few days ago and I was able to run Perl scripts from the Apache. I read this doc to do it : http://perl.apache.org/docs/2.0/user/intro/start_fast.html But while keeping on reading docs about Perl programming, I discovered that it is possible to install modules directly from the command line 'perl -MCPAN -e shell'. After installing some modules I didn't find in Ubuntu packages, the path to per changed from originally /usr/bin/perl to /usr/local/bin/perl . As a consequence,on my server where the perl scripts, I changed the path to the Perl interpreter from /usr/bin/perl to /usr/local/bin/perl. I have also reinstalled the Ubuntu mod_perl package but no change. Finally, each time I want to run a simple Perl script on my server, my browser asks me to download it. I don't know what to do. Thanks you very much for your help. Sami Ubuntu uses it own software to install packages. The problem is its defaults are not the same as CPAN's. You can also do it the hard way. That is download the package from CPAN and uncompress it with: tar xvf package Change directory to the one created and read the README* and INSTALL* files. They should tell you how to change the defaults values, specially the place to install the package. Then: perl change_default_options configure.PL make make test # if the tests fail, don't do the next line sudo make install -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: problems with CGI and mod_perl
sfantar a écrit : Hello everyone I have started since today learning how to write cgi in Perl with this doc : http://users.easystreet.com/ovid/cgi_course/lessons/lesson_one.html I am running ubuntu on my pc and I installed the package mod_perl made by ubuntu a few days ago and I was able to run Perl scripts from the Apache. I read this doc to do it : http://perl.apache.org/docs/2.0/user/intro/start_fast.html But while keeping on reading docs about Perl programming, I discovered that it is possible to install modules directly from the command line 'perl -MCPAN -e shell'. After installing some modules I didn't find in Ubuntu packages, the path to per changed from originally /usr/bin/perl to /usr/local/bin/perl . As a consequence,on my server where the perl scripts, I changed the path to the Perl interpreter from /usr/bin/perl to /usr/local/bin/perl. I have also reinstalled the Ubuntu mod_perl package but no change. Finally, each time I want to run a simple Perl script on my server, my browser asks me to download it. I don't know what to do. Thanks you very much for your help. Sami Sorry for my silly question. Eventually, I found out where the problem is. I didn't write the correct url in my browser to launch a perl script from my server. I took the time to read again and carefully what I wrote in my apache config file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the problems with my CGI script
Hello, Use of uninitialized value in concatenation (.) or string at cgi_7.pl line 31. /htmlp /This is your name Use of uninitialized value in concatenation (.) or string at cgi_7.pl line 35. Line 31 and 35 are using data that in uninitialized. For instance calling param() on a parameter that has not been passed to the script will return a value thats been uninitialized. For instanc e it appears its the name so calling your script with ?name=bob at the end of the url will make sure name is initialized. Alternatively you can check for that and assign an appropriate value my $name = param('name') || ''; or better yet handle it: if(defined $name) { # if its valid , HTMLescape it and print it # otherwise tell them they did bad :) } else { # ask them for theri name } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the problems with my CGI script
Anthony Ettinger wrote: my $name = param('name') || ''; if(defined $name) { # if its valid , HTMLescape it and print it # otherwise tell them they did bad :) } else { # ask them for theri name } definitely the better way to handle it, although you don't need the || unless you want a default value. Setting it as empty is still a yeah, I did || ''; so his uninitialized value woudl go away, but in that case the if(defined $name) could just be if($name) value, so you potentially could have empty values in your database. if Thats what the if its valid part is for :) (defined($name)) would be better, but can be rather cumbersome. Actually it not that cumbersome (all the parens look really bad IMHO...), just change || ''; to ; above and voila fool proof and it looks slick! :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the problems with my CGI script
my $name = param('name') || ''; if(defined $name) { # if its valid , HTMLescape it and print it # otherwise tell them they did bad :) } else { # ask them for theri name } definitely the better way to handle it, although you don't need the || unless you want a default value. Setting it as empty is still a value, so you potentially could have empty values in your database. if (defined($name)) would be better, but can be rather cumbersome. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- 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 Perl syntax
Mr. Shawn H. Corey [EMAIL PROTECTED] writes: use Data::Dumper; print Dumper $self; Thanks for the pointers... I haven't read it all yet but still trying to get this script to run. It is inlined at the end. Introducing your code causes a new failure and nothing is printed. [What I'm asking here is quite a lot so if you want to just tell me to bug off, that would be taken in stride, and understood] errors before: Use of uninitialized value in split at ./gen_images line 39. Output path is '/var/www/locahost/htdocs/photo/data/' Use of uninitialized value in open at lib/Database.pm line 216. Use of uninitialized value in concatenation (.) or string at lib/Database.pm line 216. Cannot read database : No such file or directory at lib/Database.pm line 216. === === errors after introducing the dump: I inserted: use Data::Dumper; print Dumper $self; exit; Global symbol $self requires explicit package name at ./gen_images line 32. Execution of ./gen_images aborted due to compilation errors. === I'm not making any sense of this. The error at 216 lib/Database.pm involves still more of the OOP heirogliphics, Leaving that alone for now. I'd like to just find out what is supposed to be getting passed into this script. I'll post only one of the two cfg files being read and you'll see it has very little in it. The documentation with this script appears to be out of sync with actual script so hasn't been much help. I suspect my problem revolve around miss placing parts of the package. I'm hoping if I can just get an idea what is supposed to be getting read in and shifted off, I can piece together where things are supposed to be. First the script, followed by one of two cfg files. = ./gen_images #!/usr/bin/perl -w # This script generates the differently sized images for the ShowArt gallery. # It needs ImageMagick installed. # See art/cfg/gen_images.cfg for options and settings. ## # Nothing more needs to be changed below. # This should really use Getopt::Long... use lib 'lib'; use strict; use File::Spec; use File::Find; use Database; # the database support use ArtShow::Config; use English; my $VERSION = '0.14'; BEGIN { $|++; # output buffer off } my $cfg = ArtShow::Config-new(art/cfg/gen_images.cfg); my $art_cfg = ArtShow::Config-new(art/cfg/artshow.cfg); my $first = shift || 1; # first ID to generate my $last = shift || 0; # last ID to generate my $sizes = shift || $cfg-{sizes}-[0]; my $output = shift || $cfg-{output_dir}-[0]; my $org_dir = $cfg-{org_dir}-[0]; my $print = shift || 0; my @sizes = split (/\s*,\s*/ , $sizes); print Output path is '$output'\n; # read the database my $db = Database-new( { file = $cfg-{database}-[0], } ); my $id = $db-first() || 0; # set iterator to first item while ($id != $first) { $id = $db-next(); die (ID $first is not in the database) if !defined $id; } print Running as user $UID, group $GID\n; while (defined $id) { # find the proper input file my $item = $db-item($id); my $name = $item-[2]; $name .= '.jpg' unless $name =~ /\.(tif|jpg|png)$/; my $f = File::Spec-catfile ($org_dir, $id, $name); if (!-f $f) { `./copy_org`; } print Extracting EXIF for image ID $id from:\n '$f'\n; my $image_exif = $f; $image_exif =~ s/\.(png|tif)$/.jpg/; # extract EXIF data my $exif_file = $art_cfg-{exif_dir}-[0]/$id.txt; `./exif $image_exif $exif_file`; print $id: ; my $qs = { 1280 = 90, 1024 = 77, 800 = 76, 640 = 75, 480 = 74, 320 = 73, 240 = 70, 200 = 70, 128 = 70, 100 = 69, 80 = 68, 64 = 67 }; foreach my $size ( @sizes ) { my $o = File::Spec-catfile( $output, $id, $id.'_' . $size . '.jpg'); # make the dir where we need to put the file in my $o_dir = File::Spec-catdir( $output, $id); print Creating $o_dir\n and mkdir $o_dir unless -d $o_dir; chmod 0777, $o_dir; $item-[14] = '' if !defined $item-[14]; my @sharp_factor = (split (/\s*,\s*/, $item-[14] || '1.2,1.2')); $sharp_factor[0] = '1.1' if $size 240; $sharp_factor[0] = '1.05' if $size 128; $sharp_factor[1] = '' if $size 240; my $geo = $size; # rotation $item-[15] = '' if !defined $item-[15]; my $rot = ''; if (($item-[15]||'') ne '') { $rot = -rotate $item-[15] ; $geo = int($size * 0.75 * 0.75) if $item-[15] =~ /^(90|270)$/; } my $scale = ''; $scale = 'scale 0.8,0.8' if $size 240; $scale = 'scale 1.1,1.1' if $size 640; $scale = 'scale 1.2,1.2' if $size 800; $scale = 'scale 2.5,2.5' if $size 1024; my $fscale = ($size / 2400) * 1.6; # 2400 = 1.5, 4800 = 3 $fscale = ($size / 2400) * 1.2 if $rot; # rotated images are smaller (75%) $scale =
Re: reading Perl syntax
On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: $self-_read_file($self-{file}) $self is an blessed reference to an object (used from inside that object) $self-_read_file() is the subroutine to call defined inside that object $self-{'file'}; is a reference to a hash defined inside the object. It's confusing, but if you ignore the $self and think of it as a standalone top-down script, it makes more sense. The syntax {} is for a hashref, it's just an un-named hashref inside that object. my $foo = new Foo; print $foo-getFooKey(); $foo-setFooKey('new value'); print $foo-getFooKey(); package Foo; sub new { my $class = shift; #new Foo where Foo is the class name $self = bless {}, $class; $self-{'fookey'} = 'some value here'; #hashref accessible only within Package Foo; return $self; } sub getFooKey { my $self = shift; return $self-{'fookey'}; } sub setFooKey { my $self = shift; if (@_== 1) { #if there's another param, set that as the value $self-{'fookey'} = shift; } return $self; } 1; -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- 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 Perl syntax
[EMAIL PROTECTED] writes: I'll post only one of the two cfg files being read and you'll see it has very little in it. The documentation with this script appears to be out of sync with actual script so hasn't been much help. I suspect my problem revolve around miss placing parts of the package. I'm hoping if I can just get an idea what is supposed to be getting read in and shifted off, I can piece together where things are supposed to be. Gack, didn't inline the cfg so here it is gen_images.cfg: == # Main config file for gen_images from ArtShow # Were are your original files located (subdirs are automatically searched). # The base name for each image is specified in the database. input_dir = /var/www/localhost/cgi-bin/examples # Where to put the output files? output_dir = /var/www/locahost/htdocs/photo/data/ # The various (c) strings - adjust them accordingly! # For the (internal) image file comment: (set this always!) copyright_internal = (c) by Tels bloodgate.com 2003 All Rights Reserved. # The longer string for bigger image versions copyright_long = (c) by [EMAIL PROTECTED] 2003 # The shorter version for smaller image versions copyright_short = (c) Tels bloodgate.com 2003 -- 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 Perl syntax
Anthony Ettinger [EMAIL PROTECTED] writes: The syntax {} is for a hashref, it's just an un-named hashref inside that object. my $foo = new Foo; print $foo-getFooKey(); $foo-setFooKey('new value'); print $foo-getFooKey(); Thanks for the demo... I'm in well over my head here but the name of this group includes `beginner' so I guess this is the place for me. I didn't really understand your comments and I guess the code is supposed to run and print something so I can see what it is doing. It doesn't run here and erros out with: Can't locate object method within via package Package (perhaps you forgot to load Package?) at ./myOOP.pl line 15. -- 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 Perl syntax
just execute it with perl -wl foo or add the shebang line: #!/usr/bin/perl -w On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Anthony Ettinger [EMAIL PROTECTED] writes: The syntax {} is for a hashref, it's just an un-named hashref inside that object. my $foo = new Foo; print $foo-getFooKey(); $foo-setFooKey('new value'); print $foo-getFooKey(); Thanks for the demo... I'm in well over my head here but the name of this group includes `beginner' so I guess this is the place for me. I didn't really understand your comments and I guess the code is supposed to run and print something so I can see what it is doing. It doesn't run here and erros out with: Can't locate object method within via package Package (perhaps you forgot to load Package?) at ./myOOP.pl line 15. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
further infos about inherited classes
Hello I would like to know if we have to install one class before the inherited classes. For instance, Do I have to install CGI before CGI::Pretty to make this work or Can I install it alone? I hope my question is clear. Thanks in advance for your help. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: further infos about inherited classes
On Tue, 2006-06-06 at 20:51 +0200, sfantar wrote: Hello I would like to know if we have to install one class before the inherited classes. For instance, Do I have to install CGI before CGI::Pretty to make this work or Can I install it alone? I hope my question is clear. Thanks in advance for your help. You can install it alone. Remember T.I.T.S. (Try It To See). use CGI::Pretty qw( :standard :xhtml *table *Tr *th *td *ul *ol *dl *div ); use CGI::Carp qw( fatalsToBrowser ); Note that if you `use POSIX;` do it before you `use CGI;` or `use CGI::Pretty;` -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- 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 Perl syntax
On Tue, 2006-06-06 at 11:44 -0700, Anthony Ettinger wrote: just execute it with perl -wl foo or add the shebang line: #!/usr/bin/perl -w Your script should start with: #!/usr/bin/perl use strict; use warnings; -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- 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 Perl syntax
Anthony Ettinger [EMAIL PROTECTED] writes: just execute it with perl -wl foo or add the shebang line: #!/usr/bin/perl -w Yes, I had done that prior to posting error output The erroring script looks like: === #!/usr/local/bin/perl -w my $foo = new Foo; print $foo-getFooKey(); $foo-setFooKey('new value'); print $foo-getFooKey(); package Foo; sub new { my $class = shift; #new Foo where Foo is the class name $self = bless {}, $class; $self-{'fookey'} = 'some value here'; #hashref accessible only within Package Foo; return $self; } sub getFooKey { my $self = shift; return $self-{'fookey'}; } sub setFooKey { my $self = shift; if (@_== 1) { #if there's another param, set that as the value $self-{'fookey'} = shift; } return $self; } 1; = Outputs: Can't locate object method within via package Package (perhaps you forgot to load Package?) at ./myOOP.pl line 15. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
ksh in a perl program
Hello, Can I include a korn shell script in a perl program? I have done the following but I get a compilation failed error. abc is the ksh script. - require /home/xxx/yyy/abc; Error: syntax error at /home/xxx/yyy/abc line 3, near . Compilation failed in require at createPatch.pl line 11. - Thanks Regards, Lakshmi 952-833-1220 -- 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 Perl syntax
The line below was folded, and $self-{'fookey'} = 'some value here'; #hashref accessible only within Package Foo; the Perl interpreter is seeing within Package Foo; Outputs: Can't locate object method within via package Package (perhaps you forgot to load Package?) at ./myOOP.pl line 15. -- 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 Perl syntax
On Tue, 2006-06-06 at 13:13 -0500, [EMAIL PROTECTED] wrote: Mr. Shawn H. Corey [EMAIL PROTECTED] writes: use Data::Dumper; print Dumper $self; Thanks for the pointers... I haven't read it all yet but still trying to get this script to run. It is inlined at the end. Introducing your code causes a new failure and nothing is printed. [What I'm asking here is quite a lot so if you want to just tell me to bug off, that would be taken in stride, and understood] Learning to use Object-Oriented Perl is difficult. The problem is that since we have seen your script, it's hard to tell you exactly what needs to be done. errors before: Use of uninitialized value in split at ./gen_images line 39. Output path is '/var/www/locahost/htdocs/photo/data/' Use of uninitialized value in open at lib/Database.pm line 216. Use of uninitialized value in concatenation (.) or string at lib/Database.pm line 216. Cannot read database : No such file or directory at lib/Database.pm line 216. === === errors after introducing the dump: I inserted: use Data::Dumper; print Dumper $self; exit; Global symbol $self requires explicit package name at ./gen_images line 32. Execution of ./gen_images aborted due to compilation errors. The line: print Dumper $self; should be just before the line you posted in your earlier post: $self-_read_file($self-{file}); === I'm not making any sense of this. The error at 216 lib/Database.pm involves still more of the OOP heirogliphics, Leaving that alone for now. I'd like to just find out what is supposed to be getting passed into this script. I'll post only one of the two cfg files being read and you'll see it has very little in it. The documentation with this script appears to be out of sync with actual script so hasn't been much help. I suspect my problem revolve around miss placing parts of the package. I'm hoping if I can just get an idea what is supposed to be getting read in and shifted off, I can piece together where things are supposed to be. First the script, followed by one of two cfg files. = ./gen_images #!/usr/bin/perl -w # This script generates the differently sized images for the ShowArt gallery. # It needs ImageMagick installed. # See art/cfg/gen_images.cfg for options and settings. ## # Nothing more needs to be changed below. # This should really use Getopt::Long... use lib 'lib'; use strict; use File::Spec; use File::Find; use Database; # the database support These two modules are not standard: use ArtShow::Config; use English; my $VERSION = '0.14'; BEGIN { $|++; # output buffer off Bad idea. Most OSes do the right thing without this. You will only want to turn this on for a socket or a pipe, and only if the software on the other side reads a character at a time and responds instantly to a single character. See `perldoc perlvar` and search for '$OUTPUT_AUTOFLUSH` } my $cfg = ArtShow::Config-new(art/cfg/gen_images.cfg); my $art_cfg = ArtShow::Config-new(art/cfg/artshow.cfg); my $first = shift || 1; # first ID to generate my $last = shift || 0;# last ID to generate my $sizes = shift || $cfg-{sizes}-[0]; my $output = shift || $cfg-{output_dir}-[0]; my $org_dir = $cfg-{org_dir}-[0]; my $print = shift || 0; my @sizes = split (/\s*,\s*/ , $sizes); print Output path is '$output'\n; # read the database my $db = Database-new( { file = $cfg-{database}-[0], } ); my $id = $db-first() || 0; # set iterator to first item while ($id != $first) { $id = $db-next(); die (ID $first is not in the database) if !defined $id; } print Running as user $UID, group $GID\n; while (defined $id) { # find the proper input file my $item = $db-item($id); my $name = $item-[2]; $name .= '.jpg' unless $name =~ /\.(tif|jpg|png)$/; my $f = File::Spec-catfile ($org_dir, $id, $name); if (!-f $f) { `./copy_org`; } print Extracting EXIF for image ID $id from:\n '$f'\n; my $image_exif = $f; $image_exif =~ s/\.(png|tif)$/.jpg/; # extract EXIF data my $exif_file = $art_cfg-{exif_dir}-[0]/$id.txt; `./exif $image_exif $exif_file`; print $id: ; my $qs = { 1280 = 90, 1024 = 77, 800 = 76, 640 = 75, 480 = 74, 320 = 73, 240 = 70, 200 = 70, 128 = 70, 100 = 69, 80 = 68, 64 = 67 }; foreach my $size ( @sizes ) { my $o = File::Spec-catfile( $output, $id, $id.'_' . $size . '.jpg'); # make the dir where we need to put the file in my $o_dir = File::Spec-catdir( $output, $id); print Creating $o_dir\n and mkdir $o_dir unless -d $o_dir; chmod 0777, $o_dir; $item-[14] = '' if !defined $item-[14]; my
Re: ksh in a perl program
On 6/6/06, Lakshmi Sailaja [EMAIL PROTECTED] wrote: Can I include a korn shell script in a perl program? Not include, but you certainly can execute a shell script from within a Perl program. I have done the following but I get a compilation failed error. abc is the ksh script. - require /home/xxx/yyy/abc; 'require' is to load *Perl* modules - your script as you said is for ksh. Even though Perl has a lot of the natural feeling of shell scripts, it does not parse shell scripting language. Many scripts may be translated to Perl with little additional work (possibly adding a bunch of quotes and colons). You may try something like system /home/xxx/yyy/abc; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ksh in a perl program
On Tue, 2006-06-06 at 14:06 -0500, Lakshmi Sailaja wrote: Hello, Can I include a korn shell script in a perl program? I have done the following but I get a compilation failed error. abc is the ksh script. - require /home/xxx/yyy/abc; Error: syntax error at /home/xxx/yyy/abc line 3, near . Compilation failed in require at createPatch.pl line 11. - No, you would have to use a system() or a backtic: system( '/home/xxx/yyy/abc' ); # output not important or my @output = `home/xxx/yyy/abc`; # output saved in @output See `perldoc -f system` and `perldoc perlop` and search for Quote and Quote-like Operators -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: further infos about inherited classes
Mr. Shawn H. Corey a écrit : On Tue, 2006-06-06 at 20:51 +0200, sfantar wrote: Hello I would like to know if we have to install one class before the inherited classes. For instance, Do I have to install CGI before CGI::Pretty to make this work or Can I install it alone? I hope my question is clear. Thanks in advance for your help. You can install it alone. Remember T.I.T.S. (Try It To See). use CGI::Pretty qw( :standard :xhtml *table *Tr *th *td *ul *ol *dl *div ); use CGI::Carp qw( fatalsToBrowser ); Note that if you `use POSIX;` do it before you `use CGI;` or `use CGI::Pretty;` I agree with you about TITS but unfortunately I am just a beginner and I don't want my OS to become a real mess ;-) What is POSIX exactly? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ksh in a perl program
Adriano Ferreira wrote: On 6/6/06, Lakshmi Sailaja [EMAIL PROTECTED] wrote: Can I include a korn shell script in a perl program? Not include, but you certainly can execute a shell script from within a Perl program. I have done the following but I get a compilation failed error. abc is the ksh script. - require /home/xxx/yyy/abc; 'require' is to load *Perl* modules - your script as you said is for ksh. Even though Perl has a lot of the natural feeling of shell scripts, it does not parse shell scripting language. Many scripts may be translated to Perl with little additional work (possibly adding a bunch of quotes and colons). You may try something like system /home/xxx/yyy/abc; It wouldn't hurt to test for the permissions on the file to make sure you can execute it before calling it. -- Rance Hall System Administrator Nebraska Turkey Growers 1-308-468-5711, ext. 106 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: ksh in a perl program
Thanks a million for the response. I wanted to include the shell script, abc, as I want to access a variable. The shell script, abc, actually takes a value (val) from the user. I want to use that value (val) in my perl porgram. Is that possible? ie., I will now call abc in my perl program using system /home/xxx/yyy/abc; The script, abc, asks for a value, val, from the user. After its execution, I want to use val in my perl program. Can you suggest the procedure to use val in my Perl program? Thanks Regards, Lakshmi 952-833-1220 -Original Message- From: Adriano Ferreira [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 06, 2006 2:14 PM To: [EMAIL PROTECTED]; beginners@perl.org Subject: Re: ksh in a perl program On 6/6/06, Lakshmi Sailaja [EMAIL PROTECTED] wrote: Can I include a korn shell script in a perl program? Not include, but you certainly can execute a shell script from within a Perl program. I have done the following but I get a compilation failed error. abc is the ksh script. - require /home/xxx/yyy/abc; 'require' is to load *Perl* modules - your script as you said is for ksh. Even though Perl has a lot of the natural feeling of shell scripts, it does not parse shell scripting language. Many scripts may be translated to Perl with little additional work (possibly adding a bunch of quotes and colons). You may try something like system /home/xxx/yyy/abc; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ksh in a perl program
On 6/6/06, Lakshmi Sailaja [EMAIL PROTECTED] wrote: I wanted to include the shell script, abc, as I want to access a variable. The shell script, abc, actually takes a value (val) from the user. I want to use that value (val) in my perl porgram. Is that possible? Perl may take a value from the user as well, and probably with more sophistication than a shell script. ie., I will now call abc in my perl program using system /home/xxx/yyy/abc; The script, abc, asks for a value, val, from the user. After its execution, I want to use val in my perl program. Can you suggest the procedure to use val in my Perl program? But if you insist, one of the more simple ways would be to make the shell script echo the value just entered by the user, which would be caught by Perl in a backquote construction: `/home/xxx/yyy/abc` which replaces the call to system. -- 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 Perl syntax
There's a good book PHP5 Patterns and Object Oriented Programming which I found very instrumental in my understanding of object-oriented programming, before applying it to Perl. There are of course Perl books on the subject, and the perldocs, but I found PHP's object oriented support to be less cryptic than Perl's. It was easier for me than biting off Perl syntax and OO-Perl at the same time. http://www.chovy.com/open-source/php-5-objects-patterns-and-practice-book-review/ -- 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 Perl syntax
Adriano Ferreira [EMAIL PROTECTED] writes: the Perl interpreter is seeing within Package Foo; Gack, yes I see it now... I should have noticed that but it slid right by my unpracticed eye. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
Mr. Shawn H. Corey [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Tue, 2006-06-06 at 18:59 +0800, joseph wrote: All, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); $output_file =~ s/\r//g; # chomp only removes linefeed characters \n # BTW, there is no such thing as a newline; # it is either a linefeed: \n ASCII LF 0x0A # or a carriage return: \r ASCII CR 0x0D I still have to dig on this topic, i assume it works the same way like the sample on a book like this # chomp($file = `date`); open(FL,$output_file) or die Can't open file $!\n; ... or die cannot open file '$output_file': $!\n; # print out the contents so you can see exactly what it contains. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file: FilesystemSize Used Avail Use% Mounted on /dev/cciss/c0d0p7 1.9G 215M 1.6G 12% / /dev/cciss/c0d0p8 12G 9.8G 1.4G 87% /backup /dev/cciss/c0d0p1 96M 16M 76M 17% /boot /dev/cciss/c0d0p2 38G 24G 12G 66% /home none 1.9G 0 1.8G 0% /dev/shm No such file or directory #It's present right? Thanks for input. my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); push @list,$mounted,$percent; } %disk =(@list); delete $disk{Mounted}; foreach (sort keys %disk) { my $value = $disk{$_}; print \t $_ = $value \n; } -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Multiple Page Scrape
Thanks, but complicated for true beginners. First issue was which of three choices was XML::Simple - I chose to install XML-Simple-DTD Reader over XML-Simpler or Test-XML-Simple. I later read that XML::Simple probably comes with active Perl. Then I read the FAQ for XML::Simple and found that Although you can get by without using any options, you shouldn't even consider using XML::Simple in production until you know what these two options do: forcearray keyattr I'm starting to understand hashes, but sample code would help. Thank you. Ken On Tue, 06 Jun 2006 11:58:21 -0400, Anthony Ettinger [EMAIL PROTECTED] wrote: Since it's native xml format, I would use XML::Simple to parse it into a hash, then you can format however you want by looping through the hash. On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The script below scrapes a House of Representatives vote page which is in xml and saves it in a spreadsheet which is best opened as an xls read only. How can I: 1) scrape multiple vote pages into individual spreadsheets with a single script? 2) Only scrape columns C, F, G, H in the result here? I'd also prefer to have the spreadsheet as a csv, but that doesn't work by just changing *.xls to *.csv Thanks in advance. Ken #!/bin/perl use strict; use warnings; use WWW::Mechanize; my $output_dir = c:/training/bc; my $starting_url = http://clerk.house.gov/evs/2005/roll667.xml;; my $browser = WWW::Mechanize-new(); $browser-get( $starting_url ); foreach my $line (split(/[\n\r]+/, $browser-content)) { print $line;} open OUT, $output_dir/vote667.xls or die Can't open file:$!; foreach my $line (split(/[\n\r]+/, $browser-content)) { print OUT $line;} close OUT; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
John W. Krahn [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] joseph wrote: All, Hello, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); `df -h` does not return a file name, it returns the same output as if you had run the command 'df -h' on the command line. open(FL,$output_file) or die Can't open file $!\n; my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { There are two basic ways to do what you want: 1. for ( `df -h` ) { ... } 2. open FL, 'df -h |' or die Cannot open df pipe: $!; while ( FL ) { ... } close FL or warn $! ? Error closing df pipe: $! : Exit status $? from df; ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); You are only using two of the values so you can simplify that to: my ( $percent, $mounted ) = ( split )[ -2, -1 ]; push @list,$mounted,$percent; You don't need the array, you can assign directly to the hash: $disk{ $mounted } = $percent unless $mounted eq 'Mounted'; } %disk =(@list); delete $disk{Mounted}; John -- use Perl; program fulfillment Noted, thanks.. for all the helpful feedback it makes my learning stage worthwhile. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error (Closed)
Muma W. [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] joseph wrote: All, Just like to ask for correction on what's wrong with my script it gives spit out this error when i run it. Unsuccessful open on filename containing newline at disksize.pl line 8. Can't open file No such file or directory But it runs without this error whenever i feed it up when an existing file output by df-h. ex:## open(FL,path/toactual/file) or die blabalha; Does this mean it can't trap the output of `df-h`? Here's the script### #!/usr/bin/perl use strict; use warnings; chomp(my $output_file = `df -h`); Df can return multiple lines. I'd suspect that your string $output_file has several embedded newlines in it at this point. Chomp will only remove that last (not embedded) newline. open(FL,$output_file) or die Can't open file $!\n; my @list; my %disk; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage); while(FL) { ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_); push @list,$mounted,$percent; You might not need the intermediate list: $disk{$mounted} = $percent; } %disk =(@list); delete $disk{Mounted}; foreach (sort keys %disk) { my $value = $disk{$_}; print \t $_ = $value \n; } I'd do it like this: use strict; use warnings; use Data::Dumper; my %disk; for (`df -h`) { next if ! m{/}; my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage) = split /\s+/, $_; $disk{$mounted} = $percent; } print Dumper(\%disk); __END__ You'll notice that the backticks operator (``), in a list context, returns a list containing each line as a separate list element. Since you only seem to need two elements from the list returned by split(), you could change the two lines after the m{/} to this: my @list = split /\s+/, $_; $disk{$list[5]} = $list[4]; HTH Thank you, your way resemble with the first option John Krahn reply..i'm just late to close the thread due to timezone difference still i appreciate your effort. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Newline error
Xavier Noria [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Jun 6, 2006, at 14:16, John W. Krahn wrote: Mr. Shawn H. Corey wrote: $output_file =~ s/\r//g; # chomp only removes linefeed characters \n # BTW, there is no such thing as a newline; # it is either a linefeed: \n ASCII LF 0x0A # or a carriage return: \r ASCII CR 0x0D \n is inherited from the C programming language and is the newline escape sequence. On Unix and Unix-like systems the newline is equivalent to the ASCII line feed character but on other systems it could be one or more different characters. To be more precise, \n in Perl is eq \012 everywhere except in Mac OS pre-X, where it is eq \015. In CRLF platforms like Win32 \n is transparently converted to CRLF on writing and back on reading by PerlIO in text mode. Thus, in a regular line-oriented script like while (my $line = FH) { # work with $line } $line ends with \n but does not contain a pair CRLF (assuming native conventions in the input). On the other direction, the string foo\n has length 4 in all systems. When you print that string into a file in text mode on Windows the bytes on disk have an extra \015, but that's transparent to the programmer. That's the point of using \n as logical/portable newline in Perl. I have written an article about newlines in Perl not yet published. All those fine details are explained there. -- fxn --expect me to read it..do give me a link once done, thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
defaults
Can someone explain what: $pi ||= 3; ...means? I just saw it in Programming Perl (pp 540), but it doesn't explain it. Thx! - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: defaults
Bryan R Harris wrote: Can someone explain what: $pi ||= 3; ...means? I just saw it in Programming Perl (pp 540), but it doesn't explain it. Thx! || is the logical OR operator (see perldoc perlop) which says that if $pi is TRUE then keep the current value of $pi but if $pi is FALSE then assign 3 to $pi. That could also be written as: unless ( $pi ) { $pi = 3; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: defaults
Can someone explain what: $pi ||= 3; ...means? I just saw it in Programming Perl (pp 540), but it doesn't explain it. Thx! || is the logical OR operator (see perldoc perlop) which says that if $pi is TRUE then keep the current value of $pi but if $pi is FALSE then assign 3 to $pi. That could also be written as: unless ( $pi ) { $pi = 3; } Aah, I see now. Just like the following pairs of commands do equivalent things: $pi += 3 $pi = $pi + 3 $pi ||= 3 $pi = $pi || 3 Is there an = also? How about or=? (I can't think of why I'd need it, but I'm just curious if perl is converting left anything= right to left = left anything right.) Thanks! - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: defaults
Bryan R Harris wrote: : Is there an = also? How about or=? All perl operators are listed in the 'perlop' file. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 Perl syntax
Mr. Shawn H. Corey [EMAIL PROTECTED] writes: [...] Harry wrote: Introducing your code causes a new failure and nothing is printed. Shawn wrote: The line: print Dumper $self; should be just before the line you posted in your earlier post: $self-_read_file($self-{file}); I'm really botching this up... I got so confused here I put your code into the wrong script entirely. Once inserted where it belongs in /cgi-bin/lib/Database.pm, when I run the calling script at: /cgi-bin/gen_images I get output different by a couple lines and those lines still don't tell much about what is supposed to be in $self. == Error output: root # ./gen_images Use of uninitialized value in split at ./gen_images line 39. Output path is '/var/www/locahost/htdocs/photo/data/' $VAR1 = bless( { 'is_reversed' = 0, 'file' = undef }, 'Database' ); Use of uninitialized value in open at lib/Database.pm line 219. Use of uninitialized value in concatenation (.) or string at lib/Database.pm line 219. Cannot read database : No such file or directory at lib/Database.pm line 219. === End Error output The Dumper code you supplied cause the $VAR1 section. I'm not making any sense of this. This still holds and to your comments about the difficulty of OOP perl, it is definitely well above my skill level and this is not the best way to undertake learning it. However, I believe in this case it isn't really required to learn so much OOP as just to understand what this script is expecting to find and where. I'm guess there are only small adjustments needed since I know something close to this very code is running on a server at http://bloodgate.com/perl/art.html And the package I have is offered as a working product... so again guessing the author has gotten most of it right and I'm doing small things wrong. I'm having no luck whatever contacting the author, hence my posts here. I really need to get a nice gallery type setup running for my work with video and still pics to exchange and share source pics and images. The one running at the above address is very much like what I need. If you are still interested enough to look at a few more files I have posted the whole setup here with only a change in the name /cgi-bin/ http://home.jtan.com/~reader/mycgi-bin/ There you can see /mycgi-bin/gen_images which is the script that is failing and its call to /mycgi-bin/lib/Database.pm where the line: $self-_read_file($self-{file}); was taken from. It may not be the most convenient presentation but the files are there to view. What I'm looking for is some guidance on what this setup expects to find and where. I've included the INSTALL file from the distro too, which explains some of it. [...] Bad idea. Most OSes do the right thing without this. You will only want to turn this on for a socket or a pipe, and only if the software on the other side reads a character at a time and responds instantly to a single character. See `perldoc perlvar` and search for '$OUTPUT_AUTOFLUSH` Point taken and prointer appreciated -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Windows: Fork and run a process in the background
Greetings. I'd like to trigger an application to open ( Acrobat Reader ), and *not* freeze my perl app while it's open. Under Linux, I do: system ( evince /path/to/pdf.pdf ); The ampersand does what I need. This doesn't work under Windows. Is there a cheap nasty workaround? -- Daniel Kasak IT Developer NUS Consulting Group Level 5, 77 Pacific Highway North Sydney, NSW, Australia 2060 T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989 email: [EMAIL PROTECTED] website: http://www.nusconsulting.com.au -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Windows: Fork and run a process in the background
Try this: system( start evince /path/to/pdf.pdf ); Both cheap and nasty. -Original Message- From: Daniel Kasak [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 06, 2006 5:37 PM To: beginners@perl.org Subject: Windows: Fork and run a process in the background Greetings. I'd like to trigger an application to open ( Acrobat Reader ), and *not* freeze my perl app while it's open. Under Linux, I do: system ( evince /path/to/pdf.pdf ); The ampersand does what I need. This doesn't work under Windows. Is there a cheap nasty workaround? -- Daniel Kasak IT Developer NUS Consulting Group Level 5, 77 Pacific Highway North Sydney, NSW, Australia 2060 T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989 email: [EMAIL PROTECTED] website: http://www.nusconsulting.com.au -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Windows: Fork and run a process in the background
Timothy Johnson wrote: Try this: system( start evince /path/to/pdf.pdf ); Both cheap and nasty. That does it. Thanks :) -- Daniel Kasak IT Developer NUS Consulting Group Level 5, 77 Pacific Highway North Sydney, NSW, Australia 2060 T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989 email: [EMAIL PROTECTED] website: http://www.nusconsulting.com.au -- 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 Perl syntax
On Tue, 2006-06-06 at 19:35 -0500, [EMAIL PROTECTED] wrote: Mr. Shawn H. Corey [EMAIL PROTECTED] writes: [...] Harry wrote: Introducing your code causes a new failure and nothing is printed. Shawn wrote: The line: print Dumper $self; should be just before the line you posted in your earlier post: $self-_read_file($self-{file}); I'm really botching this up... I got so confused here I put your code into the wrong script entirely. Once inserted where it belongs in /cgi-bin/lib/Database.pm, when I run the calling script at: /cgi-bin/gen_images I get output different by a couple lines and those lines still don't tell much about what is supposed to be in $self. == Error output: root # ./gen_images Use of uninitialized value in split at ./gen_images line 39. Output path is '/var/www/locahost/htdocs/photo/data/' $VAR1 = bless( { 'is_reversed' = 0, 'file' = undef }, 'Database' ); Use of uninitialized value in open at lib/Database.pm line 219. Use of uninitialized value in concatenation (.) or string at lib/Database.pm line 219. Cannot read database : No such file or directory at lib/Database.pm line 219. === End Error output The Dumper code you supplied cause the $VAR1 section. Yes, Dumper() calls its first variable VAR1 (it calls its second VAR2, etc.). This tells more than you know. The line: 'file' = undef, means that somewhere in your code (or the class) that 'file' was actually assigned a value (the value being undef). If not, then 'file' would not appear in the dump. Try: grep -w file Database.pm If on MS DOS: perl -n -e /\bfile\b/ print Database.pm -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- 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 Perl syntax
Mr. Shawn H. Corey [EMAIL PROTECTED] writes: [...] Yes, Dumper() calls its first variable VAR1 (it calls its second VAR2, etc.). This tells more than you know. The line: 'file' = undef, means that somewhere in your code (or the class) that 'file' was actually assigned a value (the value being undef). If not, then 'file' would not appear in the dump. Try: grep -w file Database.pm If on MS DOS: perl -n -e /\bfile\b/ print Database.pm What I want here is to unwind the hash that is inside $self hoping to then understand what is supposed to be happening and where stuff needs to be to fill the hash. $file is one of them. It appears from a grep -nw file lib/Database.pm that file is assinged a value by one of those scary shift clauses where you can't tell what in the heck is being shifted. I think it must be our friend $self again. Thats part of what is so confusing here... things run in circles making it difficult to see what is supposed to be happening. 46: $self-{file} = $args-{file}; 48: $self-_read_file($self-{file}); ** = 214: my $file = shift; 216: open FILE, $file or die (Cannot read database $file: $!); 564: # locks the lockfile, reads the counter file, see update_counters() for 568: # lock the view file 650: # unlock the file 697:my $db = Database-new( { file = 'art/data/photo.lst' } ); 712:filepath and file name of the database file 765:back to disk. Make sure to call C$db-unlock() to unlock the file afterwards. 769:$view = Database-read_counters( $file ); 771:Reads in the list of 'views counters' from C$file, with locking and merges 841:Use a real database compared to a flat text file for performance reasons. 849:See the LICENSE file in the distributon for the exact license this work -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: defaults
Bryan R Harris wrote: Can someone explain what: $pi ||= 3; ...means? I just saw it in Programming Perl (pp 540), but it doesn't explain it. Thx! || is the logical OR operator (see perldoc perlop) which says that if $pi is TRUE then keep the current value of $pi but if $pi is FALSE then assign 3 to $pi. That could also be written as: unless ( $pi ) { $pi = 3; } Aah, I see now. Just like the following pairs of commands do equivalent things: $pi += 3 $pi = $pi + 3 $pi ||= 3 $pi = $pi || 3 Is there an = also? perldoc perlop [snip] Assignment Operators = is the ordinary assignment operator. Assignment operators work as in C. That is, $a += 2; is equivalent to $a = $a + 2; although without duplicating any side effects that dereferencing the lvalue might trigger, such as from tie(). Other assignment operators work similarly. The following are recognized: **=+=*==== -=/=|==||= .=%=^= x= Although these are grouped by family, they all have the precedence of assignment. Unlike in C, the scalar assignment operator produces a valid lvalue. Modifying an assignment is equivalent to doing the assignment and then modifying the variable that was assigned to. This is useful for modifying a copy of something, like this: ($tmp = $global) =~ tr [A-Z] [a-z]; Likewise, ($a += 2) *= 3; is equivalent to $a += 2; $a *= 3; Similarly, a list assignment in list context produces the list of lvalues assigned to, and a list assignment in scalar context returns the number of elements produced by the expression on the right hand side of the assignment. How about or=? As you can see from the documentation above, no. (I can't think of why I'd need it, but I'm just curious if perl is converting left anything= right to left = left anything right.) No. If anything it would convert $x = $x OP $y to $x OP= $y because the OP= operators are usually more efficient, and I know that perl converts $x++ to ++$x, if there are no side effects, because ++$x is more efficient. If you really need to understand why they are more efficient you need an understanding of assembly language and the C programming language. :-) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response