Re: Unicode
might be try this, use encoding utf-8, STDOUT = utf-8; Octavian Rasnita wrote: Hi all, I have a problem printing a file encoded as UTF8. I have tried using the following script: use Unicode::String qw(utf8); my $text = astaSTAz; my $t = utf8($text); print $t; The result printed on the screen or in a file is just az and not the whole string. I would like those non english special chars be converted as UTF8 chars. Do you know what is the problem? Thank you. Teddy, teddy.fcc.ro [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
Can't locate GD.pm in @INC + cpan install GD problems???
Hi, I'm trying to use a perl script which need GD, GDGraph, GDGraph3d and GDTextUtil. I found already some messages in the archives of this mailing list ans especially the msg 09105. The guy had the same problem as me so I followed the answer msg 09107 but it didn't succeed with me ... When I checked the rpms in my machine (Linux Redhat8.0), I got the following: [EMAIL PROTECTED] /]# rpm -qa | grep gd gdbm-1.8.0-18 gdm-2.4.0.7-13 gd-devel-1.8.4-9 gd-1.8.4-9 gdk-pixbuf-gnome-0.18.0-4 gdk-pixbuf-devel-0.18.0-4 gd-progs-1.8.4-9 sysklogd-1.4.1-10 gdk-pixbuf-0.18.0-4 gdbm-devel-1.8.0-18 gdb-5.2.1-4 libgd-2.0.20-2 So it seems that my RPMs are ok or ? When I run my perl script, this is what I got: --- --#perl mrtg_total.pl /test.cfg Can't locate GD.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at /usr/lib/perl5/site_perl/5.8.0/GD/Graph.pm line 38. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/GD/Graph.pm line 38. Compilation failed in require at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/axestype.pm line 18. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/axestype.pm line 18. Compilation failed in require at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/bars.pm line 18. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/bars.pm line 18. Compilation failed in require at /usr/local/bin/mrtg_total.pl line 154. BEGIN failed--compilation aborted at /usr/local/bin/mrtg_total.pl line 154. - So I try the solution given in the msg 09107 and I did that: [EMAIL PROTECTED] download]#perl -MCPAN -e shell then cpan install GD I got this (sorry for the length): - cpan install GD CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Database was generated on Tue, 10 Feb 2004 04:49:55 GMT Running install for module GD Running make for L/LD/LDS/GD-2.12.tar.gz CPAN: Digest::MD5 loaded ok CPAN: Compress::Zlib loaded ok Checksum for /root/.cpan/sources/authors/id/L/LD/LDS/GD-2.12.tar.gz ok Scanning cache /root/.cpan/build for sizes GD-2.12/ GD-2.12/t/ GD-2.12/t/GD.t GD-2.12/t/Polyline.t GD-2.12/t/test.out.10.png-1 GD-2.12/t/test.out.10.png-2 GD-2.12/t/test.out.1.png GD-2.12/t/test.out.2.png GD-2.12/t/test.out.3.png GD-2.12/t/test.out.4.png GD-2.12/t/test.out.5.png GD-2.12/t/test.out.6.png GD-2.12/t/test.out.7.png GD-2.12/t/test.out.8.png GD-2.12/t/test.out.9.png GD-2.12/t/Generic.ttf GD-2.12/t/frog.jpg GD-2.12/t/frog.xpm GD-2.12/t/test.out.8.png-1 GD-2.12/t/test.out.8.png-2 GD-2.12/t/test.out.8.png-3 GD-2.12/t/test.out.8.png-4 GD-2.12/t/test.out.8.png-5 GD-2.12/t/tile.png GD-2.12/t/palettemap.png GD-2.12/GD/ GD-2.12/GD/Polyline.pm GD-2.12/GD.pm GD-2.12/GD.xs GD-2.12/demos/ GD-2.12/demos/brushes.pl GD-2.12/demos/font_list.png GD-2.12/demos/fonttest GD-2.12/demos/polys.pl GD-2.12/demos/fills.pl GD-2.12/demos/truetype_test GD-2.12/demos/shapes.pl GD-2.12/demos/copies.pl GD-2.12/demos/ttf.pl GD-2.12/demos/gd_example.cgi GD-2.12/demos/tile.png GD-2.12/demos/polyline.pl GD-2.12/demos/transform.pl GD-2.12/qd.pl GD-2.12/README GD-2.12/Makefile.PL GD-2.12/README.QUICKDRAW GD-2.12/typemap GD-2.12/bdf_scripts/ GD-2.12/bdf_scripts/README GD-2.12/bdf_scripts/cvtbdf.pl GD-2.12/bdf_scripts/bdftogd GD-2.12/README.unix GD-2.12/ChangeLog GD-2.12/MANIFEST Removing previously used /root/.cpan/build/GD-2.12 CPAN.pm: Going to build L/LD/LDS/GD-2.12.tar.gz NOTICE: This module requires libgd 2.0.12 or higher. it will NOT work with earlier versions. See www.cpan.org for versions of GD that are compatible with earlier versions of libgd. If you are using Math::Trig 1.01 or lower, it has a bug that causes a prerequisite not found warning to be issued. You may safely ignore this warning. Type perl Makefile.PL -h for command-line option summary Where is libgd installed? [/usr/lib] Please choose the features that match how libgd was built: Build JPEG support? [y] y Build FreeType support? [y] y Build XPM support? [y] y If you experience compile problems, please check the @INC, @LIBPATH and @LIBS arrays defined in Makefile.PL and manually adjust, if necessary. Checking if your kit is complete... Looks good Writing Makefile for GD cp GD/Polyline.pm blib/lib/GD/Polyline.pm cp qd.pl blib/lib/qd.pl cp GD.pm blib/lib/GD.pm AutoSplitting blib/lib/GD.pm (blib/lib/auto/GD) /usr/bin/perl /usr/lib/perl5/5.8.0/ExtUtils/xsubpp -typemap
Pbm: Can't locate GD.pm in @INC + cpan install GD problems??? (precedent msg in the archives not usefull)
Hi, I'm trying to use a perl script which need GD, GDGraph, GDGraph3d and GDTextUtil. I found already some messages in the archives of this mailing list ans especially the msg 09105. The guy had the same problem as me so I followed the answer msg 09107 but it didn't succeed with me ... When I checked the rpms in my machine (Linux Redhat8.0), I got the following: [EMAIL PROTECTED] /]# rpm -qa | grep gd gdbm-1.8.0-18 gdm-2.4.0.7-13 gd-devel-1.8.4-9 gd-1.8.4-9 gdk-pixbuf-gnome-0.18.0-4 gdk-pixbuf-devel-0.18.0-4 gd-progs-1.8.4-9 sysklogd-1.4.1-10 gdk-pixbuf-0.18.0-4 gdbm-devel-1.8.0-18 gdb-5.2.1-4 libgd-2.0.20-2 So it seems that my RPMs are ok or ? When I run my perl script, this is what I got: --- --#perl mrtg_total.pl /test.cfg Can't locate GD.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at /usr/lib/perl5/site_perl/5.8.0/GD/Graph.pm line 38. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/GD/Graph.pm line 38. Compilation failed in require at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/axestype.pm line 18. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/axestype.pm line 18. Compilation failed in require at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/bars.pm line 18. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/bars.pm line 18. Compilation failed in require at /usr/local/bin/mrtg_total.pl line 154. BEGIN failed--compilation aborted at /usr/local/bin/mrtg_total.pl line 154. - So I try the solution given in the msg 09107 and I did that: [EMAIL PROTECTED] download]#perl -MCPAN -e shell then cpan install GD I got this (sorry for the length): - cpan install GD CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Database was generated on Tue, 10 Feb 2004 04:49:55 GMT Running install for module GD Running make for L/LD/LDS/GD-2.12.tar.gz CPAN: Digest::MD5 loaded ok CPAN: Compress::Zlib loaded ok Checksum for /root/.cpan/sources/authors/id/L/LD/LDS/GD-2.12.tar.gz ok Scanning cache /root/.cpan/build for sizes GD-2.12/ GD-2.12/t/ GD-2.12/t/GD.t GD-2.12/t/Polyline.t GD-2.12/t/test.out.10.png-1 GD-2.12/t/test.out.10.png-2 GD-2.12/t/test.out.1.png GD-2.12/t/test.out.2.png GD-2.12/t/test.out.3.png GD-2.12/t/test.out.4.png GD-2.12/t/test.out.5.png GD-2.12/t/test.out.6.png GD-2.12/t/test.out.7.png GD-2.12/t/test.out.8.png GD-2.12/t/test.out.9.png GD-2.12/t/Generic.ttf GD-2.12/t/frog.jpg GD-2.12/t/frog.xpm GD-2.12/t/test.out.8.png-1 GD-2.12/t/test.out.8.png-2 GD-2.12/t/test.out.8.png-3 GD-2.12/t/test.out.8.png-4 GD-2.12/t/test.out.8.png-5 GD-2.12/t/tile.png GD-2.12/t/palettemap.png GD-2.12/GD/ GD-2.12/GD/Polyline.pm GD-2.12/GD.pm GD-2.12/GD.xs GD-2.12/demos/ GD-2.12/demos/brushes.pl GD-2.12/demos/font_list.png GD-2.12/demos/fonttest GD-2.12/demos/polys.pl GD-2.12/demos/fills.pl GD-2.12/demos/truetype_test GD-2.12/demos/shapes.pl GD-2.12/demos/copies.pl GD-2.12/demos/ttf.pl GD-2.12/demos/gd_example.cgi GD-2.12/demos/tile.png GD-2.12/demos/polyline.pl GD-2.12/demos/transform.pl GD-2.12/qd.pl GD-2.12/README GD-2.12/Makefile.PL GD-2.12/README.QUICKDRAW GD-2.12/typemap GD-2.12/bdf_scripts/ GD-2.12/bdf_scripts/README GD-2.12/bdf_scripts/cvtbdf.pl GD-2.12/bdf_scripts/bdftogd GD-2.12/README.unix GD-2.12/ChangeLog GD-2.12/MANIFEST Removing previously used /root/.cpan/build/GD-2.12 CPAN.pm: Going to build L/LD/LDS/GD-2.12.tar.gz NOTICE: This module requires libgd 2.0.12 or higher. it will NOT work with earlier versions. See www.cpan.org for versions of GD that are compatible with earlier versions of libgd. If you are using Math::Trig 1.01 or lower, it has a bug that causes a prerequisite not found warning to be issued. You may safely ignore this warning. Type perl Makefile.PL -h for command-line option summary Where is libgd installed? [/usr/lib] Please choose the features that match how libgd was built: Build JPEG support? [y] y Build FreeType support? [y] y Build XPM support? [y] y If you experience compile problems, please check the @INC, @LIBPATH and @LIBS arrays defined in Makefile.PL and manually adjust, if necessary. Checking if your kit is complete... Looks good Writing Makefile for GD cp GD/Polyline.pm blib/lib/GD/Polyline.pm cp qd.pl blib/lib/qd.pl cp GD.pm blib/lib/GD.pm AutoSplitting blib/lib/GD.pm (blib/lib/auto/GD) /usr/bin/perl /usr/lib/perl5/5.8.0/ExtUtils/xsubpp -typemap
Regex..
Could some good samaritan help me out with this pls... I am trying to find a regular expression for the below string.. ExchangeName = MOLD%20WEST ExpectedDate = LineStatus = Z Status = NO 200 OK - and i am trying with something as below: $line =~ /([a-zA-Z_0-9.]+)\s*=\s*([a-zA-Z_0-9.]+)/; I am able to fix the first three lines; but the last line (200 OK - ) is giving me problems... I also tried. $line =~ /([a-zA-Z_0-9.]+)\s*=\-\s*([a-zA-Z_0-9.]+)/; but it gives me an error as i m trying put the above values in a hash. regards, Ajitpal Singh, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RFC - implementing callbacks
Hi folks, Thanks to previous threads on this list, I'm making pretty good progress on what is my first OOP project. The improvements I've made after feedback are: * logical bounderies between containers and contents (sub-classes) * nicer interface functions * (starting to use) named parameters, with option to still use positional * Classes only know about themselves and sub-classes I now have the following structure (roughly). Trainset is the top level class and is the container for everything . Program |-Trainset (everything) |- Box ( individual signalbox) |-Gantry ( signal gantry) | |-Signal |-Tcb (Length of Track Circuit) | |-Track (single length of track) |-Lever (lever in signalbox) One of the points made in the previous threads was that there should be no need for sub-classes to have a link back to it's parent, and through the correct splitting of functions (inter-instance in class, intra-instance within container) I've done this okay. My problem is now: I need to be able to pass to the Trainset instance a ref to a callback within Program (to refresh a PerlTk window, or to send a signal to a model railway controller). This callback then needs to be triggered by the Trainset instance itself, but also from Signals, Gantries, and Tcbs. Other than going back to holding a ref to the Trainset instance, or worse still, copying the ref to the callback to every object, how can I do this? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Trouble with -T switch
Thanks Jan, It worked. $ENV{'PATH'} = ; open (SENDMAIL, |/usr/sbin/sendmail -oi -t -odq); Are you aware of [EMAIL PROTECTED] I posted my CGI questions to [EMAIL PROTECTED] until someone notified me of this list. Yes, I am. And I don't know why I didn't post my question there. But on the other hand using taint mode applies none CGI scripts as well, so I thought this list might be appropriate. Grettings Marcus - Jan -- If all else fails read the instructions. - Donald Knuth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Date manipulation
hi list, i'd like to try a first perl-script that should: -define todays date -define todays date minus one week -find in a special directory files, that contain ddmmyy -remove them ..since i am an absolute beginner in programming...i think, if i can read out this directory, i can find the files with regexp. But: how can i find out the Systems-Date with Perl? Which format has it? Is there a perlman-page? (I was looking, but didn't find...) otherwise i would have to do a bigger workaround in a shell-script (but i would like to learn perl...) Hope for any help, thank you Roger -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Date manipulation
From: Roger Grosswiler [EMAIL PROTECTED] Subject: Date manipulation Date: Tue, 10 Feb 2004 11:21:15 +0100 (CET) hi list, i'd like to try a first perl-script that should: -define todays date -define todays date minus one week -find in a special directory files, that contain ddmmyy -remove them ..since i am an absolute beginner in programming...i think, if i can read out this directory, i can find the files with regexp. But: how can i find out the Systems-Date with Perl? Which format has it? Is there a perlman-page? (I was looking, but didn't find...) Read the perlfunc man page. It will contain detailed information about time related issues: Time-related functions gmtime, localtime, time, times The localtime and time are your functions. Some code: $nowstring = localtime ; ## current sys-time ($wday,$mon,$day,$timestr,$year) = split(/ /,$nowstring) ; ($hh,$mm,$ss) = split(/:/,$timestr) ; Try to run this, print the vars, and you will see how it works. Use the time function to time to get the seconds from Jan 1st 1970. You will be able to do any calculation you want. From man perlfunc: timeReturns the number of non-leap seconds since whatever time the system considers to be the epoch (thats 00:00:00, January 1, 1904 for Mac OS, and 00:00:00 UTC, January 1, 1970 for most other systems). Suitable for feeding to gmtime and localtime. For measuring time in better granularity than one second, you may use either the Time::HiRes module from CPAN, or if you have gettimeofday(2), you may be able to use the syscall interface of Perl, see perlfaq8 for details. Good luck, Gabaux Linux is like a wigwam: no gates, no windows, and an apache inside! -- 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..
Ajit P Singh wrote: Could some good samaritan help me out with this pls... I am trying to find a regular expression for the below string.. ExchangeName = MOLD%20WEST ExpectedDate = LineStatus = Z Status = NO 200 OK - and i am trying with something as below: $line =~ /([a-zA-Z_0-9.]+)\s*=\s*([a-zA-Z_0-9.]+)/; I am able to fix the first three lines; but the last line (200 OK - ) is giving me problems... I also tried. $line =~ /([a-zA-Z_0-9.]+)\s*=\-\s*([a-zA-Z_0-9.]+)/; but it gives me an error as i m trying put the above values in a hash. Hi Ajit. I'm not clear what result you want for the last line, but this should help. Cheers, Rob use strict; use warnings; while (DATA) { if (/(.*?)\s*-/) { printf \$1 = %s\n, $1; } elsif (/([^\s=]+).*?([^\s=]+)/) { printf \$1 = %-14s \$2 = %s\n, $1, $2; } } __DATA__ ExchangeName = MOLD%20WEST ExpectedDate = LineStatus = Z Status = NO 200 OK - **OUTPUT $1 = ExchangeName $2 = MOLD%20WEST $1 = ExpectedDate $2 = $1 = LineStatus $2 = Z $1 = Status $2 = NO $1 = 200 OK -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
problem with Multipart module
I am trying to use the Net::SMTP::Multipart to send attachments (word doc) and the encoding is getting mangled on non-linux machines If I send it to myself everything is fine (either external or via my mail server) this appears to the relevant part of the modules sub FileAttach { my $self = shift; foreach my $file (@_) { unless (-f $file) { carp 'Net::SMTP::Multipart:FileAttach: unable to find file $file'; next; } my($bytesread,$buffer,$data,$total); open(FH,$file) || carp Net::SMTP::Multipart:FileAttach: failed to open $file\n; binmode(FH); while ( ($bytesread=sysread(FH,$buffer, 1024))==1024 ){ $total += $bytesread; # 500K Limit on Upload Images to prevent buffer overflow #if (($total/1024) 500){ # printf TooBig %s\n,$total/1024; # $toobig = 1; # last; #} $data .= $buffer; } if ($bytesread) { $data .= $buffer; $total += $bytesread ; } #print File Size: $total bytes\n; close FH; if ($data){ $self-datasend(--$b\n); $self-datasend(Content-Type: ; name=\$file\\n); $self-datasend(Content-Transfer-Encoding: base64\n); $self-datasend(Content-Disposition: attachment; =filename= \$file\\n\n); $self-datasend(encode_base64($data)); $self-datasend(--$b\n); } } } and this my script $smtp-Header( To = $mailing1[2], Subj = Management Meeting, From = [EMAIL PROTECTED], From = [EMAIL PROTECTED]); $smtp-Text(text); $smtp-FileAttach (doc_file.doc); $smtp-End(); any help appreciated -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Updating an array within a hash
Hi Everybdy, I am stuck in a problem for which I need your help. My problem spins around adding an element in an array within a hash. I have a hash declared as $hash{1[EMAIL PROTECTED]; now I want to add an element to it within a loop. How would I do this? I would be highly grateful to you if you could help me. Regards Soumyadeep __ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
can't use CPAN with Mandrake 9.2
This might be better off on a Mandrake list, but I was hoping for an answer here (esp. since I'm already subscribed here :-) I tried to install Getopt:Simple via CPAN on my new Mandrake 9.2 box. I get this Error: Unable to locate installed Perl libraries or Perl source code. It is recommended that you install perl in a standard location before building extensions. Some precompiled versions of perl do not contain these header files, so you cannot build extensions. In such a case, please build and install your perl from a fresh perl distribution. It usually solves this kind of problem. (You get this message, because MakeMaker could not find /usr/lib/perl5/5.8.1/i386-linux-thread-multi/CORE/perl.h) As the note indicates - there is no perl.h in the indicated directory (but the directory is there) Do I really have to reinstall perl? It works and is in /usr/bin which seems normal to me Brian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Array containment
Hi all, a while ago, I wrote a little subroutine to test wether a given element is in a given array: sub contains { my $result = 0; my $contained = shift; foreach (@_) { if ($_ eq $contained){ $result = 1; } } $result; } Now I found a nicer solution in Learning Perl Objects, References Modules and adapted it: sub contains { my $contained = shift; my $result = grep { $contained eq $_ } @_; } Smart. But immediately after giving this example, Randal notes that this is not the best solution for testing large arrays. Can anyone give me a hint to what he might have meant? Or, to put it this way: Randal, what did you think of writing this? Thanks, Jan -- The day Microsoft makes something that doesn't suck is the day they start selling vacuum cleaners. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Updating an array within a hash
Soumyadeep nandi wrote: Hi Everybdy, I am stuck in a problem for which I need your help. My problem spins around adding an element in an array within a hash. I have a hash declared as $hash{1[EMAIL PROTECTED]; now I want to add an element to it within a loop. How would I do this? I would be highly grateful to you if you could help me. Your syntax puts a number (the number of elements in @array into $hash{1}. I guess you want to set an array reference as the hash key's value: $hash{1} = [EMAIL PROTECTED]; In that case, you can just push @{$hash{1}}, $_ for (...list goes here...); to push into the array referenced by $hash{1}. Best, Jan -- These are my principles and if you don't like them... well, I have others. - Groucho Marx -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Updating an array within a hash
Hi Everybdy, I am stuck in a problem for which I need your help. My problem spins around adding an element in an array within a hash. I have a hash declared as $hash{1[EMAIL PROTECTED]; now I want to add an element to it within a loop. How would I do this? I would be highly grateful to you if you could help me. Hi, I'm not sure you can just go hash = array as they're somewhat different, in the same way you can't go scalar = array (you can but it won't do what you think). But you can assign the hash the reference of the array. For example: $hash{1} = [EMAIL PROTECTED]; Or: push(@{$hash{1}}, @array); Then to loop through the array whose reference is assigned to $hash{1} you can do: foreach(@{$hash{1}}) { # do something with $_ } Cheers! This email has been scanned for all viruses by the MessageLabs Email Security System. For more information on a proactive email security service working around the clock, around the globe, visit http://www.messagelabs.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: problem with Multipart module
From: mike [EMAIL PROTECTED] I am trying to use the Net::SMTP::Multipart to send attachments (word doc) and the encoding is getting mangled on non-linux machines If I send it to myself everything is fine (either external or via my mail server) this appears to the relevant part of the modules sub FileAttach { ... Looks OK (I don't think it's the best idea to load the whole file into memory, encode it in one go and then send it. For big files it would be better to read+encode+send in chunks. IMHO of course) and this my script $smtp-Header( To = $mailing1[2], Subj = Management Meeting, From = [EMAIL PROTECTED], From = [EMAIL PROTECTED]); $smtp-Text(text); $smtp-FileAttach (doc_file.doc); $smtp-End(); Seems to be fine as well. Could you send me a test doc by your script to [EMAIL PROTECTED] Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Date manipulation
Roger Grosswiler wrote: But: how can i find out the Systems-Date with Perl? Which format has it? Is there a perlman-page? (I was looking, but didn't find...) perldoc -f localtime HTH, Jan -- There's no place like ~/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Formatting output
hi again, thanks to you, i got it with my date. so 1st point is out. i still have a short problem, as i should get my date back in the format ddmmyy and i get it in d m y (with %2d, but how to handle in vars) #!/usr/bin/perl $t1=time(); $t2=$t1 - 604800; $diff=$t1 - $t2; print Zeit 1; $t1\tZeit 2: $t2\tDifferenz: $diff\n\n; $lt1 = localtime($t1); $lt2 = localtime($t2); ($lt1sec,$lt1min,$lt1hour,$lt1mday,$lt1mon,$lt1year,$lt1wday,$lt1yday,$lt1isdst) = localtime($t1); ($lt2sec,$lt2min,$lt2hour,$lt2mday,$lt2mon,$lt2year,$lt2wday,$lt2yday,$lt2isdst) = localtime($t2); print String Localtime 1: $lt1\n; print String Localtime 2: $lt2\n; print \n\n\nParsing Lines\n\n; print Sekunde:\t$lt1sec\t$lt2sec\n; print Minute:\t\t$lt1min\t$lt2min\n; print Stunde:\t\t$lt1hour\t$lt2hour\n; printf Tag\t\t%d\t%d\n,$lt1mday,$lt2mday; printf Monat\t\t%d\t%d\n,$lt1mon,$lt2mon; printf Jahr\t\t%d\t%d\n,$lt1year-100,$lt2year-100; print Wday\t\t$lt1wday\t$lt2wday\n; printf Yeard.\t\t%d\t%d\n,$lt1yday+1,$lt2yday+1; print \n; printf Datumsversuch :%2d%2d%2d\n,$lt2mday,$lt2mon+1,$lt2year-100; the output is: Zeit 1; 1076418100 Zeit 2: 1075813300 Differenz: 604800 String Localtime 1: Tue Feb 10 14:01:40 2004 String Localtime 2: Tue Feb 3 14:01:40 2004 Parsing Lines Descriptionsact.Date delete.Date Sekunde:40 40 Minute: 1 1 Stunde: 14 14 Tag 10 3 Monat 1 1 Jahr4 4 Wday2 2 Yeard. 41 34 Datumsversuch : 3 2 4 ..look the last line called Datumsversuch. I should have here 030204...so i could do with some regexp and the variables the deleting of files, which are older than 7 days. Otherwise i must handle this by shell-script or manually *help thanks, Roger -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: my ($var) = IN; and my ($var); $var = IN different ?
Thind, Aman said: Hello Friends, I was just writing some code and observed that : My ($cur_line) = IN; While ($cur_line = IN) { . Even though IN is a handle of a file with many lines, control does not enter the while loop. However when I do : My ($cur_line); $cur_line = IN; While ($cur_line = IN) { . It enters the while loop as I preseume it should. Why is it so ? Value of $cur_line is the same before the while loop i.e. only 1 line is read into the variable in both the cases. When you write my ($cur_line) = IN; you put IN in list context, thus it reads all the input it can, creating a list with each element being one line of the input. You then assign this list to the list ($cur_line), which assigns the first element to $cur_line and discards the rest. What you really want is my $cur_line = IN;. Automatically adding parentheses to lexical variable declarations is not a good habit to get into. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
Jan Eden wrote: a while ago, I wrote a little subroutine to test wether a given element is in a given array: sub contains { my $result = 0; my $contained = shift; foreach (@_) { if ($_ eq $contained){ $result = 1; } } $result; } Now I found a nicer solution in Learning Perl Objects, References Modules and adapted it: sub contains { my $contained = shift; my $result = grep { $contained eq $_ } @_; } Smart. But immediately after giving this example, Randal notes that this is not the best solution for testing large arrays. Can anyone give me a hint to what he might have meant? Or, to put it this way: Randal, what did you think of writing this? Hi Jan. If you want to test a static (unchanging) array for the containment of many different values you should build a hash out of the array elements: my @data = 'a' .. 'm'; my %data_hash; @[EMAIL PROTECTED] = (); Then simply check for the existence of a hash element with the required value as a key: for (split '', 'robdixon') { if (exists $data_hash{$_}) { printf Element %s found in [EMAIL PROTECTED], $_; } else { printf Element %s isn't in [EMAIL PROTECTED], $_; } } **OUTPUT Element r isn't in @data Element o isn't in @data Element b found in @data Element d found in @data Element i found in @data Element x isn't in @data Element o isn't in @data Element n isn't in @data But this isn't practical if the hash keeps needing to be rebuilt because the array hash changed. Depending on your data it may be a good idea to start with a hash anyway, but for a general overview of the topic look at: perldoc -q array contains HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Date manipulation
On Tue, Feb 10, 2004 at 11:21:15AM +0100, Roger Grosswiler ([EMAIL PROTECTED]) wrote: hi list, i'd like to try a first perl-script that should: -define todays date -define todays date minus one week -find in a special directory files, that contain ddmmyy -remove them ..since i am an absolute beginner in programming...i think, if i can read out this directory, i can find the files with regexp. I don't have a lot of time to elaborate since I'm at work right now but this is how I handled a similar problem. I don't present this as great but it has worked for me so far. If you have questions fire away. Later, maybe tonight, I will be able to respond. Kent #!/usr/bin/perl use warnings; use strict; # epoch time three weeks ago my $t_w_a = (time - 1814400); # ILL file directory my $ill_dir = /var/www/ssl-docs/illreq; opendir(IDIR, $ill_dir) || die Can't open $ill_dir: $!; # delete any files with mtime older than 21 days while(defined(my $file = readdir IDIR)) { next if $file eq '.' or $file eq '..'; my $modified_time = (stat($ill_dir/$file))[9]; if ($modified_time = $t_w_a) { unlink($ill_dir/$file); } } closedir IDIR or die Can't close $ill_dir: $!; -- Efficiency is intelligent laziness. -David Dunham -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Using archive::tar for archiving a folder
Hello Friends, I wish to archive a folder into a .tar I've been searching through the documentation of archive::tar module but could not find a way by which I could make the .tar just by specifying the folder name (like on unix prompt tar -cvf myarchive.tar myfoldername) and not explicitly stating the filenames. Some suggestions plz... Thanx a lot aman
How to interrogate array cell?
I have an array of hashes. What function should I be using to interrogate each array cell when I want to know if it is occupied? exists seemed to do the job nicely. What about defined? Now I am curious: how would I implement a switch statement (er, I mean, set of if-elsif statements) for a hetrogeneous array where some array cells contain arrays, others integers, other hashes? I tried saying my @x; if(@x $x[$ii] %{$x[$ii]} exists $x[$ii]{xyz}){ my $z = $x[$ii]{xyz}; ...} But that did not work. There must be some function that will tell me this array cell contains a hash, this other array cell contains another array Thanks, Sieg __ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.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: Formatting output
Roger Grosswiler wrote: hi again, thanks to you, i got it with my date. so 1st point is out. i still have a short problem, as i should get my date back in the format ddmmyy and i get it in d m y (with %2d, but how to handle in vars) How about $lt2mday = sprintf(%02d, $lt2mday); perldoc -f sprintf - Jan -- There's no place like ~/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
Hi Rob, Rob Dixon wrote: Hi Jan. If you want to test a static (unchanging) array for the containment of many different values you should build a hash out of the array elements: my @data = 'a' .. 'm'; my %data_hash; @[EMAIL PROTECTED] = (); I see. But shouldn't the last line be a complete hash slice: [EMAIL PROTECTED] = (); Then simply check for the existence of a hash element with the required value as a key: for (split '', 'robdixon') { if (exists $data_hash{$_}) { printf Element %s found in [EMAIL PROTECTED], $_; } else { printf Element %s isn't in [EMAIL PROTECTED], $_; } } I thought of the exists function, but I always hesitate to use a hash if my data is not really hash-like. Thinking perlish is still on my to do list. Thank you! - Jan -- How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine dark as the new standard. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Developer Tools iTunes
Phil Dobbin wrote: On 10/02/2004, at 11:27 (GMT), wren argetlahm, [EMAIL PROTECTED] wrote: I'm a newbie to Perl on *nix and am in the process of converting from MacPerl to OSX and I've just recently downloaded the developer tools for OSX10.2 because I was under the impression that they're necessary to really use Perl on OSX (i.e. to use CPAN, Camel Bones, etc). But installing the packages'll take nearly a gig which is more space than I have on my startup partition; so I'm wondering if they really are necessary to use Perl? [...] Under 10.2 you do need the developer tools to fully utilise Perl (gcc for make files, etc). IIRC, the latest Perl (5.8.3) doesn't require the dev tools to be installed (I *think* that dependency seen off in 5.8.2) but maybe that's only on 10.3.x. The dev tools contain perldoc, gcc etc. So the CD is the easiest way to a complete Perl installation. - Jan -- Common sense is what tells you that the world is flat. -- 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 interrogate array cell?
Hi, Richard Heintze wrote: I have an array of hashes. What function should I be using to interrogate each array cell when I want to know if it is occupied? exists seemed to do the job nicely. What about defined? exists only works with hashes. Please check the recent conversation about Array containment, where Rob Dixon advised me to turn my array into a hash to use the exists function. - Jan -- There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
On Feb 10, 2004, at 5:04 AM, Jan Eden wrote: Hi all, Howdy. a while ago, I wrote a little subroutine to test wether a given element is in a given array: sub contains { my $result = 0; my $contained = shift; foreach (@_) { if ($_ eq $contained){ $result = 1; } } $result; } That works, though I would probably drop the extra variable. sub contains { my $contained = shift; foreach (@_) { return 1 if $_ eq $contained; } return 0; } Now I found a nicer solution in Learning Perl Objects, References Modules and adapted it: sub contains { my $contained = shift; my $result = grep { $contained eq $_ } @_; } Again, no need for the variable. sub contains { my $contained = shift; return grep $_ eq $contained, @_; } Smart. But immediately after giving this example, Randal notes that this is not the best solution for testing large arrays. Can anyone give me a hint to what he might have meant? Or, to put it this way: Randal, what did you think of writing this? I'm not Randal, but will I do? laughs The problem with both of your posted solutions is that they run the entire list of elements. The question is, Is $contained in there somewhere? That means that the first time we see it, we have answered that question. If we have 20,000 elements and we find it in the second slot, we waste 19,998 lookups, right? We can't fix this in the grep() version, because grep() finds ALL matches, not just the first. It must walk the list to do its job. However, I snuck in a fix for your version above. Go take a peak... James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
On Feb 10, 2004, at 8:53 AM, Jan Eden wrote: Rob Dixon wrote: @[EMAIL PROTECTED] = (); I see. But shouldn't the last line be a complete hash slice: [EMAIL PROTECTED] = (); Rob's line is a hash slice. Note the @. Yours is a simple hash lookup, one scalar value affected, thus the $. James -- 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 interrogate array cell?
Hi, Richard Heintze wrote: I have an array of hashes. What function should I be using to interrogate each array cell when I want to know if it is occupied? exists seemed to do the job nicely. What about defined? exists only works with hashes. Please check the recent conversation about Array containment, where Rob Dixon advised me to turn my array into a hash to use the exists function. Caveat version... depends on the version of Perl. Newer 'exists' can check arrays... from perldoc -f exists: Given an expression that specifies a hash element or array element, returns true if the specified element in the hash or array has ever been initialized Works at least as of 5.6.1. As to your other question, check out: perldoc -f ref You may also find, perldoc UNIVERSAL particularly 'isa' helpful... http://danconia.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: can't use CPAN with Mandrake 9.2
This might be better off on a Mandrake list, but I was hoping for an answer here (esp. since I'm already subscribed here :-) I tried to install Getopt:Simple via CPAN on my new Mandrake 9.2 box. I get this Error: Unable to locate installed Perl libraries or Perl source code. It is recommended that you install perl in a standard location before building extensions. Some precompiled versions of perl do not contain these header files, so you cannot build extensions. In such a case, please build and install your perl from a fresh perl distribution. It usually solves this kind of problem. (You get this message, because MakeMaker could not find /usr/lib/perl5/5.8.1/i386-linux-thread-multi/CORE/perl.h) As the note indicates - there is no perl.h in the indicated directory (but the directory is there) Do I really have to reinstall perl? It works and is in /usr/bin which seems normal to me Brian If mandrake is still similar to RedHat and uses RPMs or some kind of binary distribution then there might be a separate perl-dev package or some such that comes with the distro that will contain the header files that you will need. Sometimes these are only installed if you select developer packages, etc. I assume to have gotten this far you have make, gcc, etc. installed. Having said that I haven't heard of this before with respect to the base Perl install, and it would seem rather silly of Mandrake, but you never know... You may have better luck asking in a Mandrake forum about what packages you need to install to get the provided perl.h... Good luck, http://danconia.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: Array containment
James Edward Gray II wrote: That works, though I would probably drop the extra variable. sub contains { my $contained = shift; foreach (@_) { return 1 if $_ eq $contained; } return 0; } Perfect. Returns 1 as soon as it finds the element. I'm not Randal, but will I do? laughs To my experience, your postings have been highly informative. The problem with both of your posted solutions is that they run the entire list of elements. The question is, Is $contained in there somewhere? That means that the first time we see it, we have answered that question. If we have 20,000 elements and we find it in the second slot, we waste 19,998 lookups, right? We can't fix this in the grep() version, because grep() finds ALL matches, not just the first. It must walk the list to do its job. However, I snuck in a fix for your version above. Go take a peak... Your suggestion is certainly a peak in elegant programming. ;) Thanks! Jan -- Either this man is dead or my watch has stopped. - Groucho Marx -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: getting rid of space at beggining of variable
At 01:28 AM 2/12/2004 +1100, David Inglis wrote: bloggs, joe which I then spilt into 2 using @names=split(/\,/, $contact) How about: #!perl -w use strict; my $contact = bloggs, joe; @names=split(/, /, $contact); print @names; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
James Edward Gray II wrote: On Feb 10, 2004, at 8:53 AM, Jan Eden wrote: Rob Dixon wrote: @[EMAIL PROTECTED] = (); I see. But shouldn't the last line be a complete hash slice: [EMAIL PROTECTED] = (); Rob's line is a hash slice. Note the @. Yours is a simple hash lookup, one scalar value affected, thus the $. My mistake. Thanks. - Jan -- If all else fails read the instructions. - Donald Knuth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Getting croak or carp into variable ?
Hello List, I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is no way to specify anythign else besides those two. So the way it is you just do: my $res = funktion('foobarmonkey',err_doer = 'carp'); And it will do carp('what the heck is foobarmonkey'); What I'd like to do is get any errors into a variable: my $err = ''; my $res = funktion('foobarmonkey',err_doer = 'puterrorinvar'); if($err) { print Error: $err\n; print Logging error...' if(logerror($err) { print Ok\n; } else { print Failed!\n; } print Emailing Admin...; if(emailadmin($err)) { print Ok\n; } else { print Failed!\n; } # and now that we did that we can go ahead and carp, craok die, whatever } Except I can't simply specify a new function for errors because it checks for what you enter to see if its in a hash and if not defaults to one or the other. (I could modify the module but then it won't work for all) SO I guess the question is, is there a way to get carp or croak into a variable? Something like this perhaps: ? my $err = ''; putcarpinvar_on(\$err); # this is an example to illustrate what I'm shooting for it is not real my $res = funktion('foobarmonkey',err_doer = 'puterrorinvar'); putcarpinvar_off(\$err); # this is an example to illustrate what I'm shooting for it is not real if($err) { ... Any ideas? TIA Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: my ($var) = IN; and my ($var); $var = IN different ?
Thanx Paul That explains the behaviour very clearly. I rushed to my code and replaced all the my ($var) with my $var :) -Original Message- From: Paul Johnson [mailto:[EMAIL PROTECTED] Sent: 10 February 2004 19:20 To: Thind, Aman Cc: '[EMAIL PROTECTED]' Subject: Re: my ($var) = IN; and my ($var); $var = IN different ? Thind, Aman said: Hello Friends, I was just writing some code and observed that : My ($cur_line) = IN; While ($cur_line = IN) { . Even though IN is a handle of a file with many lines, control does not enter the while loop. However when I do : My ($cur_line); $cur_line = IN; While ($cur_line = IN) { . It enters the while loop as I preseume it should. Why is it so ? Value of $cur_line is the same before the while loop i.e. only 1 line is read into the variable in both the cases. When you write my ($cur_line) = IN; you put IN in list context, thus it reads all the input it can, creating a list with each element being one line of the input. You then assign this list to the list ($cur_line), which assigns the first element to $cur_line and discards the rest. What you really want is my $cur_line = IN;. Automatically adding parentheses to lexical variable declarations is not a good habit to get into. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Date manipulation
On Feb 10, 2004, at 4:21 AM, Roger Grosswiler wrote: hi list, Hello. i'd like to try a first perl-script that should: -define todays date print localtime(), \n; -define todays date minus one week print localtime( time - 60 * 60 * 24 * 7 ), \n; # depending on how you define week -find in a special directory files, that contain ddmmyy my @date = (localtime(time - 60 * 60 * 24 * 7))[3..5]; $date[1]++; $date[2] = substr $date[2] + 1900, 2; my $date = sprintf '%02u%02u%02u', @date; my $directory = 'path/to/special/dir'; opendir DIR, $directory or die Unable to open $directory; my @files = grep /$date/, readdir DIR; close DIR; -remove them foreach (@files) { unlink $directory/$_ or warn $_ could not be deleted.\n; } Hope that helps get you going. James -- 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 interrogate array cell?
On Feb 10, 2004, at 8:50 AM, Richard Heintze wrote: I have an array of hashes. What function should I be using to interrogate each array cell when I want to know if it is occupied? exists seemed to do the job nicely. What about defined? exists() tests if the slot was ever assigned to. defined() tests if the slot contains a defined value (read: not undef). It's a subtle difference and it gets a little fuzzier inside a loop, where skipped slots will come up, as long as a later slot has been assigned to. (See code below.) For that reason, I generally want defined() when talking about arrays. Now I am curious: how would I implement a switch statement (er, I mean, set of if-elsif statements) for a hetrogeneous array where some array cells contain arrays, others integers, other hashes? See if this give you some ideas: #!/usr/bin/perl use strict; use warnings; my @complex = ( [ 1, 2, 3 ], 405, { dogs = 200, cats = 16 } ); $complex[4] = qr/a regex/; print Skipped slot.\n\n unless exists $complex[3]; foreach (@complex) { unless (defined $_) { print Undefined slot.\n; next; } my $type = ref($_) || INTEGER; if ($type eq ARRAY) { print Array found: , join(, , @$_), \n; } elsif ($type eq HASH) { my %hash = %$_; print Hash Found: , join(, , map { $_ = $hash{$_} } keys %hash), \n; } elsif ($type eq INTEGER) { print Integer found: $_\n; } else { print Unknown type: $type\n; } } __END__ James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Getting croak or carp into variable ?
On Feb 10, 2004, at 9:56 AM, Dan Muey wrote: Hello List, I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is no way to specify anythign else besides those two. So the way it is you just do: my $res = funktion('foobarmonkey',err_doer = 'carp'); And it will do carp('what the heck is foobarmonkey'); What I'd like to do is get any errors into a variable: my $err = ''; my $res = funktion('foobarmonkey',err_doer = 'puterrorinvar'); if($err) { print Error: $err\n; print Logging error...' if(logerror($err) { print Ok\n; } else { print Failed!\n; } print Emailing Admin...; if(emailadmin($err)) { print Ok\n; } else { print Failed!\n; } # and now that we did that we can go ahead and carp, craok die, whatever } Except I can't simply specify a new function for errors because it checks for what you enter to see if its in a hash and if not defaults to one or the other. (I could modify the module but then it won't work for all) SO I guess the question is, is there a way to get carp or croak into a variable? Something like this perhaps: ? Maybe. Check out this one liner: perl -MCarp -e '$SIG{__WARN__} = sub { $err = shift; }; carp Error!\n; print We caught $err;' Strangely though, this did not work for me, though I expected it to: perl -MCarp -e '$SIG{__DIE__} = sub { $err = shift; }; croak Error!\n; print We caught $err;' James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Always Timing Out in Net::Telnet :(
Hello Friends, I have to run a command on my unix box through a script running on my windows m/c. Here's my code which is nothing but the example in perldoc of the module : use Net::Telnet (); $username = myusername; $passwd = mypasswd; $t = new Net::Telnet (Timeout = 10, Prompt = '/login \(dell001rs\): $/'); $t-open('my_machine_ip'); $t-login($username, $passwd); @lines = $t-cmd(who); print @lines; Now, as per the module documentation , specifying the Prompt is very essential if it is not like the default '/[\$%#] $/ ' It searches through the input stream for the prompt and performs actions accordingly. If it is not able to find the prompt in the stream, it shall time-out looking for the login prompt. When I login to my machine , the login prompt is like : login (dell001rs): And after logging in the prompt becomes : [EMAIL PROTECTED] $ What should I add after Prompt = while creating a new session ? No matter what I try it always aborts with the msg : timed-out waiting for login prompt at J:\net.pl line 10 :(( Thanx a lot Aman -Original Message- From: Thind, Aman [mailto:[EMAIL PROTECTED] Sent: 05 February 2004 10:55 To: [EMAIL PROTECTED] Subject: Remote script execution Hello Friends, I would be really grateful if someone could help me out with this. I want to write a script that when executed will get lots of details from 10 different Unix(AIX) and Windows(XP) boxes and generate a report. The details to be gathered about the machines include : 1) Names and versions of all the softwares on the machines. 2) Disk space usage. Etc... Please guide me how I could go about it... I am not aware of how a script running on 1 machine take data from commands that are to be run on other...(like rsh) Thanks in advance -aman -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: my ($var) = IN; and my ($var); $var = IN different ?
Aman == Aman Thind [EMAIL PROTECTED] writes: Aman I rushed to my code and replaced all the my ($var) with my $var :) Except that this can also break things. Witness: sub optimal { my ($first) = @_; ... } If you remove the parens there, you break the subroutine, as it will be getting the number of arguments, not the first argument. Rather than having a rule like always or never there, you should understand precisely what it is you are doing. And do the right thing. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment 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: Getting croak or carp into variable ?
On Feb 10, 2004, at 9:56 AM, Dan Muey wrote: Hello List, I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is no way to specify anythign else besides those two. So the way it is you just do: my $res = funktion('foobarmonkey',err_doer = 'carp'); And it will do carp('what the heck is foobarmonkey'); What I'd like to do is get any errors into a variable: my $err = ''; my $res = funktion('foobarmonkey',err_doer = 'puterrorinvar'); if($err) { print Error: $err\n; print Logging error...' if(logerror($err) { print Ok\n; } else { print Failed!\n; } print Emailing Admin...; if(emailadmin($err)) { print Ok\n; } else { print Failed!\n; } # and now that we did that we can go ahead and carp, craok die, whatever } Except I can't simply specify a new function for errors because it checks for what you enter to see if its in a hash and if not defaults to one or the other. (I could modify the module but then it won't work for all) SO I guess the question is, is there a way to get carp or croak into a variable? Something like this perhaps: ? Maybe. Check out this one liner: perl -MCarp -e '$SIG{__WARN__} = sub { $err = shift; }; carp Error!\n; print We caught $err;' Strangely though, this did not work for me, though I expected it to: perl -MCarp -e '$SIG{__DIE__} = sub { $err = shift; }; croak Error!\n; print We caught $err;' Oh yeah %SIG I've nvere really messed with it before. I'll check it out a bit more, thanks James! Dan James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
James wrote: On Feb 10, 2004, at 5:04 AM, Jan Eden wrote: Now I found a nicer solution in Learning Perl Objects, References Modules and adapted it: sub contains { my $contained = shift; my $result = grep { $contained eq $_ } @_; } Again, no need for the variable. sub contains { my $contained = shift; return grep $_ eq $contained, @_; } We can't fix this in the grep() version, because grep() finds ALL matches, not just the first. It must walk the list to do its job. However, I snuck in a fix for your version above. Go take a peak... What do you mean here James? All I can see is that you changed grep BLOCK into grep EXPRESSION reversed the operands of 'eq' and dropped the assignment. Am I missing something? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Program close
Hi When I run a very simple Perl program, it closes immediately after it has done. So that I can't even see the output. How can I solve this? Thanks in advance! _ De nieuwe Pirelli 2004 kalender al gezien? http://auto.msn.be/pirelli2004/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Program close
Create a simple .bat file call the Perl script and add a pause command after it. :) Ned Cunningham POS Systems Development Monro Muffler Brake 200 Holleder Parkway Rochester, NY 14615 (585) 647-6400 ext. 310 [EMAIL PROTECTED] -Original Message- From: Anthony Vanelverdinghe [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 10, 2004 12:30 PM To: [EMAIL PROTECTED] Subject:Program close Hi When I run a very simple Perl program, it closes immediately after it has done. So that I can't even see the output. How can I solve this? Thanks in advance! _ De nieuwe Pirelli 2004 kalender al gezien? http://auto.msn.be/pirelli2004/ -- 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: How to interrogate array cell?
Jan Eden wrote: Richard Heintze wrote: I have an array of hashes. What function should I be using to interrogate each array cell when I want to know if it is occupied? exists seemed to do the job nicely. What about defined? exists only works with hashes. Please check the recent conversation about Array containment, where Rob Dixon advised me to turn my array into a hash to use the exists function. Sorry if I misled you Jan, but 'exists' works on both hash and array elements. Look: use strict; use warnings; my @array; @array[2, 4] = (1, 1); for (0 .. 6) { print Element $_ Exists\n if exists $array[$_]; } **OUTPUT Element 2 Exists Element 4 Exists The only reason I suggested that you generate a hash from your array was that, if the array was invariant and you needed to do several lookups, it would be faster doing hash accesses than linear searches through the array. Look at perldoc -f exists for this topic, and make sure you read perldoc -q array contains about your previous question. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Program close
Hi Howdy When I run a very simple Perl program, it closes immediately after it has done. So that I can't even see the output. How can I solve this? Don't use windows! :) Or try executeing it from a dos prompt directly. Thanks in advance! HTH DMuey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
On Feb 10, 2004, at 11:20 AM, Rob Dixon wrote: James wrote: On Feb 10, 2004, at 5:04 AM, Jan Eden wrote: Now I found a nicer solution in Learning Perl Objects, References Modules and adapted it: sub contains { my $contained = shift; my $result = grep { $contained eq $_ } @_; } Again, no need for the variable. sub contains { my $contained = shift; return grep $_ eq $contained, @_; } We can't fix this in the grep() version, because grep() finds ALL matches, not just the first. It must walk the list to do its job. However, I snuck in a fix for your version above. Go take a peak... What do you mean here James? All I can see is that you changed grep BLOCK into grep EXPRESSION reversed the operands of 'eq' and dropped the assignment. Am I missing something? Yes, you did. :D I was talking about the fix to Jan's version, though I probably should have made that more clear. It does not need to walk the whole list. Here it is again: sub contains { my $contained = shift; foreach (@_) { return 1 if $_ eq $contained; } return 0; } I said I cannot fix the grep() version. I'm just not that cool. laughs James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Program close
-Original Message- From: Anthony Vanelverdinghe [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 10, 2004 09:30 To: [EMAIL PROTECTED] Subject: Program close Hi When I run a very simple Perl program, it closes immediately after it has done. So that I can't even see the output. How can I solve this? Thanks in advance! I created a simple sub routine which I placed in the Perl/site/lib directory. Then if I am not running from a shell, I place the use statement and the simple call to the sub which basically has a display depress any key to continue and chomp(my $MyInput = STDIN); Wags ;) ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Getting croak or carp into variable ?
perl -MCarp -e '$SIG{__WARN__} = sub { $err = shift; }; carp Error!\n; print We caught $err;' This works great! And changing $SIG{__WARN__} to '' will return default behaviour correct? (Same thign with __DIE__ ??) Strangely though, this did not work for me, though I expected it to: perl -MCarp -e '$SIG{__DIE__} = sub { $err = shift; }; croak Error!\n; print We caught $err;' Anyone have any idea how to get $SIG{__DIE__} to act like the $SIG{__WARN__} ? I'm sure it has something to do with die doing an exit() or soemthing. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Using archive::tar for archiving a folder
Aman Thind wrote: Hello Friends, I wish to archive a folder into a .tar I've been searching through the documentation of archive::tar module but could not find a way by which I could make the .tar just by specifying the folder name (like on unix prompt tar -cvf myarchive.tar myfoldername) and not explicitly stating the filenames. Archive::Tar has a class method that does exactly like that: [panda]$ perl -MArchive::Tar -e \ 'Archive::Tar-create_archive(/tmp/test.tar,0,glob(*.pl))' [panda]$ ls -l /tmp -rw-r--r--1 x x 9216 Feb 10 10:59 test.tar arguments to create_archive: 1. name of the archive you want to create. in your example, it would be myarchive.tar 2. compression level from 2 to 9. any other values will use the default level. 3. a list of files to add to the archive. in my example above, all files ending in .pl will be archived to /tmp/test.tar david -- sub'_{print@_ ;* \ = * __ ,\ \} sub'__{print@_ ;* \ = * ___ ,\ \} sub'___{print@_ ;* \ = * ,\ \} sub'{print@_,\n}{_+Just}(another)-(Perl)-(Hacker) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
On Feb 10, James Edward Gray II said: I said I cannot fix the grep() version. I'm just not that cool. I guess I'm cooler than you. ;) sub find { my $wanted = shift; my $found = 0; { grep $_ eq $wanted ++$found last, @_ } return $found; } -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Getting croak or carp into variable ?
On Feb 10, Dan Muey said: I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is no way to specify anythign else besides those two. What I'd like to do is get any errors into a variable: You want Carp::shortmess(). perldoc Carp -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
On Feb 10, Jeff 'japhy' Pinyan said: On Feb 10, James Edward Gray II said: I said I cannot fix the grep() version. I'm just not that cool. I guess I'm cooler than you. ;) sub find { my $wanted = shift; my $found = 0; { grep $_ eq $wanted ++$found last, @_ } return $found; } Or even: sub find { my $wanted = shift; grep $_ eq $wanted return(1), @_; return 0; } -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Getting croak or carp into variable ?
Hello List, I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is no way to specify anythign else besides those two. So the way it is you just do: my $res = funktion('foobarmonkey',err_doer = 'carp'); And it will do carp('what the heck is foobarmonkey'); What I'd like to do is get any errors into a variable: my $err = ''; my $res = funktion('foobarmonkey',err_doer = 'puterrorinvar'); if($err) { print Error: $err\n; print Logging error...' if(logerror($err) { print Ok\n; } else { print Failed!\n; } print Emailing Admin...; if(emailadmin($err)) { print Ok\n; } else { print Failed!\n; } # and now that we did that we can go ahead and carp, craok die, whatever } Except I can't simply specify a new function for errors because it checks for what you enter to see if its in a hash and if not defaults to one or the other. (I could modify the module but then it won't work for all) SO I guess the question is, is there a way to get carp or croak into a variable? Something like this perhaps: ? my $err = ''; putcarpinvar_on(\$err); # this is an example to illustrate what I'm shooting for it is not real my $res = funktion('foobarmonkey',err_doer = 'puterrorinvar'); putcarpinvar_off(\$err); # this is an example to illustrate what I'm shooting for it is not real if($err) { ... Any ideas? It appears you are talking about exceptions in a try/catch manner? You may want to look at perldoc -f die perldoc -f eval And see if the mess of docs there helps. It is pretty scattered at least to me, but I think it will provide what you want. An example might be, my $res = eval { call_function() }; if ($@) { # $@ contains your variable's value } # else process $res here This seems like it would simulate what you are after. Because croak is just a replacement for 'die' it should work the same way giving you the same benefits. It is really the 'eval' that is the significant part of the construct despite it being explained in the 'die' docs... I have a cursory understanding of standard exception models, and have built my own version for Perl modules that doesn't quite fit into the above (yet!), but reading the Learning Python book has helped solidify my understanding and suggesting the changes I need to make to my own implementation. Thoughts? http://danconia.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: Getting croak or carp into variable ?
I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is no way to specify anythign else besides those two. What I'd like to do is get any errors into a variable: You want Carp::shortmess(). perldoc Carp That would require modifying the module which I want to avoid. Inside a function of another package it calls either carp or croak. I'd like to get that error into a variable I can use and not die or warn from croak or carp. my $err = ''; $SIG{__WARN__} = sub { $err = shift; } $SIG{__DIE__} = sub {$err = shift; } my $res = function_that_carps_or_croaks_that_i_cant_modify(); if($err) { handle_error_my_way_instead_of_simply_carping_or_croaking($err); } $SIG{__WARN__} = ''; # or is undef or delete better?? $SIG{__DIE__} = ''; # or is undef or delete better?? That works like a charm but it does not work with $SIG{__DIE__} for some reason. It still just croaks as usual. Any ideas? -- Jeff japhy Pinyan [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: Regarding Text Widget in Perl/Tk
I tried to send off-list, but the e-mail address did not work, so I'm posting to the list: Hey, I was very impressed when this script you provided ran for me. All I did is run the first script and it creates the box nicely. I don't know much about spawning child processes. I'm on vacation and much of my Perl documentation is at home. I was wondering if you could help me get this script tied to one of my Perl programs on my Win2000 box. After much experimentation, I've changed the line open(C, ./read-own-stdout-piper 21 |) or warn $!; to open(C, round2.bat 21 |) or warn $!; round2.bat is a DOS batch file with a single line: perl round2.pl# (that is the way I run perl programs) round2.pl has: use strict; use warnings; my $number = 5.6278; my $rounded = sprintf '%.2f', $number; print $rounded\n; $|++; # SHOULD THIS LINE BE HERE? AND IT ALL WORKS! I can't just do open(C, round2.pl 21 |) or warn $!; because then it just opens round2.pl in my text editor, since that is the association I have .pl set to. I tried open(C, 'perl round2.pl' 21 |) or warn $!; but that didn't work either. That Got: prompt isn't too cool, but I'm sure I'll learn how to turn that off later. Also, it's unfortunate that copy and paste don't work in that TK box. Anyway, thanks a bunch. If there are other posts on the NG related to this, I'll see them when I get home. Mike Flannigan Houston, TX ___ Subject: Re: Regarding Text Widget in Perl/Tk Date: Fri, 30 Jan 2004 10:22:24 -0500 From: zentara [EMAIL PROTECTED] To: [EMAIL PROTECTED] On Thu, 29 Jan 2004 20:01:10 +0530, [EMAIL PROTECTED] (Vinesh Varghese) wrote: I am presently working on an Automation project where I am using Active state perl as the programming language on windows platform. For the above mentioned project I am using Perl/Tk for the GUI. I created a Text Widget and wanted to show the output from my perl code on the text box. I tried tieing the STDOUT to the text box , but the output is shown only after the program is terminated. What ever I am printing to STDOUT is accumulated and shown at once after the program is terminated. I wanted to show them as and when the program is running. I don't know where I am mistaken. Please help me in this regard. Since you don't show your code, it's hard to say what your problem is. Here is a set of programs, that do what you want. ## #!/usr/bin/perl -w use strict; use Tk; my $mw = new MainWindow; my $listbox = $mw-Scrolled(Listbox, -scrollbars = osoe, -height = 5, -selectmode = multiple) -pack(-side = left); my $start = $mw-Button( -text = 'Start', -command = \start )-pack; $mw-Button( -text = 'Exit', -command = \exit )-pack; #start external command to pipe sub start { $start-configure(-state = 'disabled'); open(C, ./read-own-stdout-piper 21 |) or warn $!; $mw-fileevent( \*C, 'readable', \doSomething ); } sub doSomething { if ( eof(C) ) {# Child closed pipe close(C); # Close parent's part of pipe, # filevent is cancelled as well wait; # Avoid zombies return; } my $text = C;# Get text from child and put it into listbox chomp($text); $listbox-insert( 'end', 'Got: ' . $text ); $listbox-see('end'); } MainLoop; __END__ ## #and here is read-own-stdout-piper #!/usr/bin/perl $|++; for my $i ( 0 .. 10) { print $i, \n; sleep 1; } __END__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Using compression on Win32 systems
Sending again to another e-mail address: It's no surprise you didn't find what you needed. The documentation on that module is poor, though not by a lack of trying by the author. He even created a FAQ later because of the confusion, but it didn't help me much either - I think due to version changes, but I'm not sure. I'm really surprised by the lack of examples on the web. I did happen to stumble across a solution - posted below. If you discover something cool with this module, please share with me. If you have further problems, feel free to contact me. Mike Flannigan ZIP: use warnings; use strict; use File::Find; use Archive::Zip; my $dir = 'c:/Copy2'; my $zip = new Archive::Zip; find sub { ( my $name = $_ ) =~ m/.*(?=\.\w{3})/; return if -d; return if /Io\.sys/; return if /Msdos\.sys/; return if /.*\.zip/i; print $name - $ \n; $zip-addFile($File::Find::name); $zip-writeToFileNamed(file.zip); } = $dir; __END__ UNZIP: use strict; use warnings; use Archive::Zip qw(:ERROR_CODES); my $dir = 'C:/Copy2'; my $zipfile = 'test.zip'; chdir $dir or die Cannot chdir $dir:$!\n; my $zip = Archive::Zip-new(); die Error reading $zipfile:$! unless $zip-read( $dir/$zipfile ) == AZ_OK; $zip-extractMember($_) for $zip-members; __END__ Subject: RE: Using compression on Win32 systems Date: Thu, 5 Feb 2004 11:35:27 -0500 From: Ned Cunningham [EMAIL PROTECTED] To: Paul Kraus [EMAIL PROTECTED], [EMAIL PROTECTED] Yes, I have looked and googled and searched aspn. Have not been able to find an example. Ned Cunningham POS Systems Development Monro Muffler Brake 200 Holleder Parkway Rochester, NY 14615 (585) 647-6400 ext. 310 [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
Perl Executable
Hi, When setting the perl executable in the code like this: #!/usr/bin/perl Is there a way of setting the path used to some variable and use it like this: #!$PERL or something along those lines? Thanks, JM -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
Jeff 'Japhy' Pinyan wrote: I said I cannot fix the grep() version. I'm just not that cool. I guess I'm cooler than you. ;) sub find { my $wanted = shift; my $found = 0; { grep $_ eq $wanted ++$found last, @_ } return $found; } Ouch! Nobody knows you can do that. Please keep it a secret or this will become an 'obfuscated Perl' group :) And these shortcut logical operators annoy me because they break the 'don't do something for its side-effects' rule. This is the same as sub find { my $wanted = shift; my $found = ''; # The preferred 'false' { grep { $found++, last if $_ eq $wanted } @_; } return $found; } Anyway, since we're in a subroutine. sub find { my $wanted = shift; grep { return 1 if $_ eq $wanted } @_; } which returns zero instead of 'undef', but hey.. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Perl Executable
Why not just do it from your shell? 'path/to/perl scriptname' works quite nicely, so why not just make an alias for the path to perl? -Original Message- From: Jeffery Malloch [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 10, 2004 11:08 AM To: '[EMAIL PROTECTED]' Subject: Perl Executable #!/usr/bin/perl Is there a way of setting the path used to some variable and use it like this: #!$PERL -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Getting croak or carp into variable ?
Dan Muey wrote: [snip] $SIG{__WARN__} = ''; # or is undef or delete better?? $SIG{__DIE__} = ''; # or is undef or delete better?? That works like a charm but it does not work with $SIG{__DIE__} for some reason. It still just croaks as usual. Any ideas? there are at least a couple of ways of doing that: #!/usr/bin/perl -w use strict; BEGIN{ use subs qw(Carp::die); use vars qw($e); sub Carp::die{ $e = Carp::die: @_ } } use Carp; croak croaking; print after croak \$e is: $e; __END__ prints: after croak $e is: Carp::die: croaking at x.pl line 10 another way to accomplish the same thing: #!/usr/bin/perl -w use strict; BEGIN{ our $e; *CORE::GLOBAL::die = sub{ $e = CORE:GLOBAL::die = @_; }; } use Carp; use vars qw($e); croak croaking; print after croak \$e is: $e; __END__ prints: after croak $e is: CORE:GLOBAL::die = croaking at x.pl line 10 i don't have time to check out the source of Carp.pm but if you do, i would suggest you go take a look as there might be a better solution to it. out of the 2 methods i described, the second one is more natural, imo. david -- sub'_{print@_ ;* \ = * __ ,\ \} sub'__{print@_ ;* \ = * ___ ,\ \} sub'___{print@_ ;* \ = * ,\ \} sub'{print@_,\n}{_+Just}(another)-(Perl)-(Hacker) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Getting croak or carp into variable ?
Dan Muey wrote: [snip] $SIG{__WARN__} = ''; # or is undef or delete better?? $SIG{__DIE__} = ''; # or is undef or delete better?? That works like a charm but it does not work with $SIG{__DIE__} for some reason. It still just croaks as usual. Any ideas? there are at least a couple of ways of doing that: #!/usr/bin/perl -w use strict; BEGIN{ use subs qw(Carp::die); use vars qw($e); sub Carp::die{ $e = Carp::die: @_ } } use Carp; croak croaking; print after croak \$e is: $e; __END__ prints: after croak $e is: Carp::die: croaking at x.pl line 10 another way to accomplish the same thing: #!/usr/bin/perl -w use strict; BEGIN{ our $e; *CORE::GLOBAL::die = sub{ $e = CORE:GLOBAL::die = @_; }; } use Carp; use vars qw($e); croak croaking; print after croak \$e is: $e; __END__ prints: after croak $e is: CORE:GLOBAL::die = croaking at x.pl line 10 i don't have time to check out the source of Carp.pm but if you do, i would suggest you go take a look as there might be a better solution to it. out of the 2 methods i described, the second one is more natural, imo. Cool, I was wondering about if that was possible, overriding the function. I'll try that out a bit and see how iut can fit into my scheme. Thanks david! david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
James, Rob, Japhy, I am impressed, really. Thank you! Rob, I read the perlfaq paragraph you mentioned and found that it proposes a solution which does not make use of 'exists': @blues = qw/azure cerulean teal turquoise lapis-lazuli/; %is_blue = (); for (@blues) { $is_blue{$_} = 1 } Now, I had the idea to combine your hash slice with this solution doing: @blues = qw/azure cerulean teal turquoise lapis-lazuli/; @[EMAIL PROTECTED] = 1; But since I have only a single number on the right side of the assignment function, only one hash element gets 1. Is there a way to automatically assign 1 to all elements with the hash slice notation (i.e. without using a loop)? I promise to drop the subject after this question. ;) Thanks again, Jan -- There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Getting croak or carp into variable ?
On Feb 10, 2004, at 11:53 AM, Dan Muey wrote: perl -MCarp -e '$SIG{__WARN__} = sub { $err = shift; }; carp Error!\n; print We caught $err;' This works great! And changing $SIG{__WARN__} to '' will return default behaviour correct? (Same thign with __DIE__ ??) Just undef them: undef $SIG{__WARN__}; Strangely though, this did not work for me, though I expected it to: perl -MCarp -e '$SIG{__DIE__} = sub { $err = shift; }; croak Error!\n; print We caught $err;' Anyone have any idea how to get $SIG{__DIE__} to act like the $SIG{__WARN__} ? I'm sure it has something to do with die doing an exit() or soemthing. This was my misunderstanding. I looked back over the __DIE__ handler. It gets called on the way down, it doesn't override the fact that you are going down. My bad. Use __WARN__. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
bad code, needs work...
Here's what I have, and I am sure there is a better way to do this... The problem I am getting is checking to see if one field matches the city, and if it does keeping it the same, however if it does not it needs to have a 1- added to the front of that field... -- CODE -- #!/usr/bin/perl -w # # # Main Functions of the script, makes calls to all of the subscripts performing the functions. # Also creates pretty output for everyone to check out. This script is designed to run after WGEN has been run. # # no warnings qw(uninitialized); $content_type = Content-Type: text/html\n\n; print ENDPAGE; [EMAIL PROTECTED] html head titleCustomer Parsing Form/title body bgcolor=white text=black BR center CUSTOMER FILE DOWNLOAD AND CONFIGURE/center HR BR This will download and create the files onto the Intranet from Stanpak. Login to Stanpak FIRST and run ROBERT and ROBERT2 from *QICLOOK to create the files this script needs to handle the rest of this process.BR ENDPAGE print Now getting the files from the server (salesa*)BRHR; #get_files; print BRHRBRfont +2IF you have done the *QICLOOK report (ROBERTC) then the files will be there for the server to download. Once those files are there and downloaded this script will get the files and put them into the flat files for inventory and *** items./fontBR; cleanup; print ENDPAGE2; This script has finished running and ALL pages should now be updated. /body /html ENDPAGE2 sub cleanup{ use strict; use warnings; my (@fields, $lng); opendir INDIR , /home/web/sales/info/test or die Can't open dir with before files:$!; #$infile = custs1; foreach my $infile (grep {!/^\./} readdir INDIR) { #read all the files in your home/sql dir #read only files that do not start with a . my ($i,$rec, $tmptxt); open INFILE, /home/web/sales/info/test/$infile or die Can't open $infile: $!; open OUTFILE, /home/multifax/everyone or die Can't open ${infile}.out at home: $!; open OUTFILE1, /home/multifax/pack-fishbait or die Can't open ${infile}.out at home: $!; open OUTFILE2, /home/multifax/pack-food or die Can't open ${infile}.out at home: $!; open OUTFILE3, /home/multifax/pack-ice_cream or die Can't open ${infile}.out at home: $!; open OUTFILE4, /home/multifax/pack-other or die Can't open ${infile}.out at home: $!; open OUTFILE5, /home/multifax/auto or die Can't open ${infile}.out at home: $!; open OUTFILE6, /home/multifax/barsupplies or die Can't open ${infile}.out at home: $!; open OUTFILE7, /home/multifax/building or die Can't open ${infile}.out at home: $!; open OUTFILE8, /home/multifax/candy or die Can't open ${infile}.out at home: $!; open OUTFILE9, /home/multifax/candy2 or die Can't open ${infile}.out at home: $!; open OUTFILE10, /home/multifax/caterer or die Can't open ${infile}.out at home: $!; open OUTFILE11, /home/multifax/pack-misc or die Can't open ${infile}.out at home: $!; open OUTFILE12, /home/multifax/coffee or die Can't open ${infile}.out at home: $!; open OUTFILE13, /home/multifax/concessions or die Can't open ${infile}.out at home: $!; open OUTFILE14, /home/multifax/dairy or die Can't open ${infile}.out at home: $!; open OUTFILE15, /home/multifax/convenience or die Can't open ${infile}.out at home: $!; open OUTFILE16, /home/multifax/fruit_produce or die Can't open ${infile}.out at home: $!; open OUTFILE17, /home/multifax/hotel or die Can't open ${infile}.out at home: $!; open OUTFILE18, /home/multifax/instit_regional or die Can't open ${infile}.out at home: $!; open OUTFILE19, /home/multifax/instit_indep or die Can't open ${infile}.out at home: $!; open OUTFILE20, /home/multifax/instit_ethnic or die Can't open ${infile}.out at home: $!; open OUTFILE21, /home/multifax/indust or die Can't open ${infile}.out at home: $!; open OUTFILE22, /home/multifax/janitorial or die Can't open ${infile}.out at home: $!; open OUTFILE23, /home/multifax/jan_cleaning or die Can't open ${infile}.out at home: $!; open OUTFILE24, /home/multifax/office or die Can't open ${infile}.out at home: $!; open OUTFILE25, /home/multifax/paper_multi or die Can't open ${infile}.out at home: $!; open OUTFILE26, /home/multifax/paper_food or die Can't open ${infile}.out at home: $!; open OUTFILE27, /home/multifax/paper_indep or die Can't open ${infile}.out at home: $!; open OUTFILE28, /home/multifax/restaurant_supply or die Can't open ${infile}.out at home: $!; open OUTFILE29, /home/multifax/vending-regional or die Can't open ${infile}.out at home: $!; open OUTFILE30, /home/multifax/vending-indep or die Can't open ${infile}.out at home: $!; open OUTFILE31, /home/multifax/all_other or die Can't open ${infile}.out at home: $!; open OUTFILE32, /home/multifax/unclassified or die Can't open ${infile}.out at home: $!; open OUTFILE33, /home/multifax/cash_grocer or die Can't open ${infile}.out at home: $!; open OUTFILE34, /home/multifax/cash_thomas-howard-green or die Can't open ${infile}.out at home: $!; open OUTFILE35,
Re: Updating an array within a hash
Jan Eden wrote: Soumyadeep nandi wrote: I am stuck in a problem for which I need your help. My problem spins around adding an element in an array within a hash. I have a hash declared as $hash{1[EMAIL PROTECTED]; now I want to add an element to it within a loop. How would I do this? I would be highly grateful to you if you could help me. Your syntax puts a number (the number of elements in @array into $hash{1}. I guess you want to set an array reference as the hash key's value: $hash{1} = [EMAIL PROTECTED]; In that case, you can just push @{$hash{1}}, $_ for (...list goes here...); to push into the array referenced by $hash{1}. The second argument of push() is a list so you don't need a for loop there. push @{$hash{1}}, (...list goes here...); :-) 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: Getting croak or carp into variable ?
there are at least a couple of ways of doing that: #!/usr/bin/perl -w use strict; BEGIN{ use subs qw(Carp::die); use vars qw($e); sub Carp::die{ $e = Carp::die: @_ } } use Carp; croak croaking; print after croak \$e is: $e; __END__ prints: after croak $e is: Carp::die: croaking at x.pl line 10 another way to accomplish the same thing: #!/usr/bin/perl -w use strict; BEGIN{ our $e; *CORE::GLOBAL::die = sub{ $e = CORE:GLOBAL::die = @_; }; } use Carp; use vars qw($e); croak croaking; print after croak \$e is: $e; __END__ prints: after croak $e is: CORE:GLOBAL::die = croaking at x.pl line 10 i don't have time to check out the source of Carp.pm but if you do, i would suggest you go take a look as there might be a better solution to it. out of the 2 methods i described, the second one is more natural, imo. Thanks that helped out abunch I believe it has me up and running! I use the Carp::die so I won't effect any real die()s just the croak()s Thanks again! Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl Documentation like Javadoc
I would like to generate methof/subroutine related documentation for a Perl project that I have just finished. What is the best way of doing it ? can you also specify which commands/executables to use for this ? Viraj B. Purang -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: bad code, needs work...
Looping is your friend :-)... Here's what I have, and I am sure there is a better way to do this... The problem I am getting is checking to see if one field matches the city, and if it does keeping it the same, however if it does not it needs to have a 1- added to the front of that field... For this specific question you may want to see the other threads about Jan's (I think) function dealing with checking whether a value is in a list of other values. -- CODE -- #!/usr/bin/perl -w # # # Main Functions of the script, makes calls to all of the subscripts performing the functions. # Also creates pretty output for everyone to check out. This script is designed to run after WGEN has been run. # # no warnings qw(uninitialized); $content_type = Content-Type: text/html\n\n; print ENDPAGE; [EMAIL PROTECTED] html head titleCustomer Parsing Form/title body bgcolor=white text=black BR center CUSTOMER FILE DOWNLOAD AND CONFIGURE/center HR BR This will download and create the files onto the Intranet from Stanpak. Login to Stanpak FIRST and run ROBERT and ROBERT2 from *QICLOOK to create the files this script needs to handle the rest of this process.BR ENDPAGE print Now getting the files from the server (salesa*)BRHR; #get_files; print BRHRBRfont +2IF you have done the *QICLOOK report (ROBERTC) then the files will be there for the server to download. Once those files are there and downloaded this script will get the files and put them into the flat files for inventory and *** items./fontBR; cleanup; print ENDPAGE2; This script has finished running and ALL pages should now be updated. /body /html ENDPAGE2 sub cleanup{ use strict; use warnings; my (@fields, $lng); opendir INDIR , /home/web/sales/info/test or die Can't open dir with before files:$!; #$infile = custs1; foreach my $infile (grep {!/^\./} readdir INDIR) { #read all the files in your home/sql dir #read only files that do not start with a . my ($i,$rec, $tmptxt); open INFILE, /home/web/sales/info/test/$infile or die Can't open $infile: $!; open OUTFILE, /home/multifax/everyone or die Can't open ${infile}.out at home: $!; snip outfile opens The outfile opens can be handled in a loop that will at least prevent the copying and pasting. You can store a FILEHANDLE to a lexical and then store that scalar into a hash, which would be a convenient way to store your output handles. Alternatively you can use IO::File and go all OOP... either way your OUTFILE opens can be handled in a loop. while (INFILE) { $rec++; $i++; chomp; @fields = split /\s*\|\s*/, $_; $fields[0] =~ s/^\s+//; $fields[1] =~ s/ /_/g; In the below test you could create an array once of the cities that match, then just grep for the value in that city list with something like, if (grep $fields[4] == $_, @cities) { $tmptxt = $fields[10]; } else { $tmptxt = '1-' . $fields[10]; } No more copying and pasting, to add a city just add it to the array. if ($fields[4] == RALEIGH){ $tmptxt = $fields[10]; } elsif ($fields[4] == CARY){ $tmptxt = $fields[10]; } elsif ($fields[4] == DURHAM){ $tmptxt = $fields[10]; } elsif ($fields[4] == APEX){ $tmptxt = $fields[10]; } elsif ($fields[4] == MORRISVILLE){ $tmptxt = $fields[10]; } elsif ($fields[4] == Holly Springs){ $tmptxt = $fields[10]; } elsif ($fields[4] == FUQUAY-VARINA){ $tmptxt = $fields[10]; } elsif ($fields[4] == FUQUAY VARINA){ $tmptxt = $fields[10]; } elsif ($fields[4] == FUQUAY-VARINA){ $tmptxt = $fields[10]; } else { $tmptxt = 1-$fields[10]; #$tmptxt .= $fields[10]; } #there is probably a way to get rid of the trailing spaces in the first entry using split,I just couldnt think of any. Huh? # $lng = @fields unless $lng; #set $lng for first record # print The following record: $i has , scalar @fields, fields as compared to $lng fields in the first record! Skip. : $_\n and next unless $lng == @fields; # poor quality control of your input data: check if all reords have the same number of fields or skip and print record otherwise. # i++; print OUTFILE42 $_| foreach (@fields); print OUTFILE [EMAIL PROTECTED]; #your trailing ID # print OUTFILE42 $_| foreach (@fields); if ($fields[11] == 102){ print OUTFILE1 [EMAIL PROTECTED]; #your trailing ID } elsif ($fields[11] == 104){ print OUTFILE2 [EMAIL PROTECTED]; #your trailing ID } snip list of prints else { print OUTFILE41 [EMAIL PROTECTED]; #your trailing ID } Again if you store the output handles to a hash, then you can look up which output handle you need to print to using the hash key. Then you only need one print. You will have to retrieve the filehandle into a simple scalar to use plain print, alternatively if they are
Re: Array containment
On Feb 10, 2004, at 2:39 PM, Jan Eden wrote: James, Rob, Japhy, I am impressed, really. Thank you! Me too. We haven't scared you off yet. :) Impressive. Rob, I read the perlfaq paragraph you mentioned and found that it proposes a solution which does not make use of 'exists': What's wrong with exists()? I like exists() and you're going to hurt it's feelings. :) @blues = qw/azure cerulean teal turquoise lapis-lazuli/; %is_blue = (); for (@blues) { $is_blue{$_} = 1 } Now, I had the idea to combine your hash slice with this solution doing: @blues = qw/azure cerulean teal turquoise lapis-lazuli/; @[EMAIL PROTECTED] = 1; @[EMAIL PROTECTED] = (1) x scalar @blues; But since I have only a single number on the right side of the assignment function, only one hash element gets 1. Is there a way to automatically assign 1 to all elements with the hash slice notation (i.e. without using a loop)? You could also use map() I guess, if you don't consider that a loop: @[EMAIL PROTECTED] = map { 1 } 0..$#blues; I promise to drop the subject after this question. ;) I don't mind. I'm not even Rob. ;) James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: bad code, needs work...
In the below test you could create an array once of the cities that match, then just grep for the value in that city list with something like, if (grep $fields[4] == $_, @cities) { $tmptxt = $fields[10]; } else { $tmptxt = '1-' . $fields[10]; } No more copying and pasting, to add a city just add it to the array. if ($fields[4] == RALEIGH){ $tmptxt = $fields[10]; } p.s. regardless of how you handle it, the above test needs to be done with 'eq' rather than '=='. == is the number equality test, 'eq' is the string equality test, which is what you are testing... same goes for in the 'grep' I provided... http://danconia.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: Perl Documentation like Javadoc
On Feb 10, 2004, at 2:51 PM, Viraj Purang wrote: I would like to generate methof/subroutine related documentation for a Perl project that I have just finished. What is the best way of doing it ? can you also specify which commands/executables to use for this ? Perl's Javadoc-like cousin is called POD. You can read about it with this command: perldoc perlpod James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
Jan Eden wrote: Rob, I read the perlfaq paragraph you mentioned and found that it proposes a solution which does not make use of 'exists': @blues = qw/azure cerulean teal turquoise lapis-lazuli/; %is_blue = (); for (@blues) { $is_blue{$_} = 1 } It's not for me to rewrite the docs (or perhaps it is?) but for (@blues) { $is_blue{$_} = 1 } does the same thing as @[EMAIL PROTECTED] = (1) x @blues; but (I would guess) the former is slower because it has a source-level loop. That means that it's the equivalent to @[EMAIL PROTECTED] = (); (which the parallel to my code) except that the value for each hash element is '1' instead of 'undef', which means that you could write the tidier if ($is_blue{$_}) instead of if (exists $is_blue{$_}) Now, I had the idea to combine your hash slice with this solution doing: @blues = qw/azure cerulean teal turquoise lapis-lazuli/; @[EMAIL PROTECTED] = 1; But since I have only a single number on the right side of the assignment function, only one hash element gets 1. Is there a way to automatically assign 1 to all elements with the hash slice notation (i.e. without using a loop)? I think I just showed you that before you asked. You need as many '1's as there are hash elements, so you need to assign 'scalar @blues' copies of the list '(1)'. @[EMAIL PROTECTED] = (1) x @blues I promise to drop the subject after this question. ;) Believe me, we're really having fun thinking around your ideas: it's better than working for a living :) While you're learning, please keep asking. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl Documentation like Javadoc
On Feb 10, 2004, at 2:51 PM, Viraj Purang wrote: I would like to generate methof/subroutine related documentation for a Perl project that I have just finished. What is the best way of doing it ? can you also specify which commands/executables to use for this ? Perl's Javadoc-like cousin is called POD. You can read about it with this command: perldoc perlpod James You may also be interested in OODoc, haven't used it personally, but Mail::Box is a pretty impressive example of it: http://search.cpan.org/~markov/OODoc-0.10/lib/OODoc.pod Conveniently written by the guy that leads Mail::Box development. http://danconia.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: Array containment
James Edward Gray II wrote: On Feb 10, 2004, at 2:39 PM, Jan Eden wrote: @blues = qw/azure cerulean teal turquoise lapis-lazuli/; %is_blue = (); for (@blues) { $is_blue{$_} = 1 } Now, I had the idea to combine your hash slice with this solution doing: @blues = qw/azure cerulean teal turquoise lapis-lazuli/; @[EMAIL PROTECTED] = 1; @[EMAIL PROTECTED] = (1) x scalar @blues; But since I have only a single number on the right side of the assignment function, only one hash element gets 1. Is there a way to automatically assign 1 to all elements with the hash slice notation (i.e. without using a loop)? You could also use map() I guess, if you don't consider that a loop: @[EMAIL PROTECTED] = map { 1 } 0..$#blues; And if you don't really need the @blues array: my %is_blue = map { $_ = 1 } qw/azure cerulean teal turquoise lapis-lazuli/; 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: RFC - implementing callbacks
On Feb 10, 2004, at 3:29 AM, Gary Stainburn wrote: Hi folks, Hello again. [snipped history] One of the points made in the previous threads was that there should be no need for sub-classes to have a link back to it's parent, and through the correct splitting of functions (inter-instance in class, intra-instance within container) I've done this okay. Let's not say you should never have links back to the parent object. I've seen places where it made fine sense. I actually have I server I've been working on that does this. Individual connections keep a link to the main server, to inform it of changes in their status, based on network reads/writes and to access server wide functionality, like logging. Generally though, what you say is a good rule of thumb. My problem is now: I need to be able to pass to the Trainset instance a ref to a callback within Program (to refresh a PerlTk window, or to send a signal to a model railway controller). This callback then needs to be triggered by the Trainset instance itself, but also from Signals, Gantries, and Tcbs. I should warn that I have no familiarity with TK, though I do have general GUI toolkit knowledge. The above sounds backwards to me. Why should Trainset objects be tied to their interface? That limits their usefulness. The interface is an interface for representing Trainset objects, right? Well, then it makes sense for that interface to maintain a link to the Trainset object it is currently representing, right? I assume TK is event driven. So, when an event happens, I would think you would access the Trainset in the event handler, make changes and update. Now, if the Trainset object is somehow being modified by an outside source (the model controller you mention perhaps), things get a little trickier. You could always poll the Trainset object every so often to see if it has changed. Polling is generally considered bad though, so possibly better would be to have the code that is somehow changing Trainset, to call an update routine on the interface. If controller signals are just another event being handled by the interface and the interface is already keeping track of the Trainset, as I believe it should, the controller event handler can pass along the change and call for a refresh. Be aware, if the GUI allows changing the Trainset and the model controller is changing the Trainset, you make have concurrent access issues to deal with. Well, maybe that will give you some new ideas. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: RFC - implementing callbacks
On Feb 10, 2004, at 3:29 AM, Gary Stainburn wrote: Hi folks, Hello again. [snipped history] One of the points made in the previous threads was that there should be no need for sub-classes to have a link back to it's parent, and through the correct splitting of functions (inter-instance in class, intra-instance within container) I've done this okay. Let's not say you should never have links back to the parent object. I've seen places where it made fine sense. I actually have I server I've been working on that does this. Individual connections keep a link to the main server, to inform it of changes in their status, based on network reads/writes and to access server wide functionality, like logging. Generally though, what you say is a good rule of thumb. My problem is now: I need to be able to pass to the Trainset instance a ref to a callback within Program (to refresh a PerlTk window, or to send a signal to a model railway controller). This callback then needs to be triggered by the Trainset instance itself, but also from Signals, Gantries, and Tcbs. I should warn that I have no familiarity with TK, though I do have general GUI toolkit knowledge. The above sounds backwards to me. Why should Trainset objects be tied to their interface? That limits their usefulness. The interface is an interface for representing Trainset objects, right? Well, then it makes sense for that interface to maintain a link to the Trainset object it is currently representing, right? I assume TK is event driven. So, when an event happens, I would think you would access the Trainset in the event handler, make changes and update. Now, if the Trainset object is somehow being modified by an outside source (the model controller you mention perhaps), things get a little trickier. You could always poll the Trainset object every so often to see if it has changed. Polling is generally considered bad though, so possibly better would be to have the code that is somehow changing Trainset, to call an update routine on the interface. If controller signals are just another event being handled by the interface and the interface is already keeping track of the Trainset, as I believe it should, the controller event handler can pass along the change and call for a refresh. Be aware, if the GUI allows changing the Trainset and the model controller is changing the Trainset, you make have concurrent access issues to deal with. Well, maybe that will give you some new ideas. I hate beating a dead horse... but this discussion of your callbacks and triggering events that are caught by a main controller, is exactly the type of thing POE was designed to handle. Essentially a central kernel is running and dispatches events that happen elsewhere in the app to their event handlers. Which works for gui events as well as other environment changes (aka like the polling mentioned above). Within individual object sessions other events can be sent to other sessions in a callback manner based on the session name through the kernel which controls all sessions, so keeping objects tied to each other directly isn't necessary, the running kernel does it for you. You may also want to check out (not sure if I have mentioned it before) Event.pm, though I prefer POE's complete buildout http://danconia.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: Perl Documentation like Javadoc
Speaking of documentaiton, is there any structured approach to documenting the get/post parameters for a perl web page? I have a main menu type of of page I have inherited. The GUI designer is not a programmer seems to have a strong preference buttons instead of links or drop down menus. Each push button represents another target page which has its own set of get/post parameters which require its own, sometimes conflicting, hidden HTML fields. The code is SO ugly because the previous programmers had no naming conventions and did not understand SQL. Is there any structured approach to say: These hidden variables are for these destinatino pages. These are the get/post parameters for this page, etc...? and Here are the get/post params this page needs? Javadoc won't even help me with this (if I was using Java). Siegfried __ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.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: Search Replace in multiple files
Hello, I came back to office after an extended weekend and realized that my words might have irked some of you. But let me explain. I agree, acquiring the 'mental tools' to do it myself is always the best way. I had tried out a few sample scripts myself (most of them failed). After spending a few hours on it my morals got weak and I could not resist the temptation to post to this group. I am always surprised by innovative solutions by the gurus in this group. Like the way to initialize all the array elements to zero - 0 x @array . These kind of solutions make me read the perldocs. I do read the archives whenever I find time, Even when I have not posted any questions. It is a pleasure to read some of your mails. I am wary of answering to any queries though. Invariably, I see a better solution in response then what I had in mind. I am learning and I will be answering like anything soon ;) Thanks, Charles K Clarkson. I understand your concerns. I will google and cpan and try hard to find the answer myself before I post to this group. Larry wall says that laziness is a virtue, but my laziness bordered on brazenness. Cheers, Chetak [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: : : I went through perldoc perlrun and saw the code. : : I thought it as a criminal waste of time to try and : modify that code for my purpose, when I can ask you : folks :-) Perhaps I am misunderstanding you, but that sounds to me like you would rather get us to do your work for free instead of you acquiring the mental tools to do it yourself. In the long run, that doesn't really help you, does it? Many of us are here to *help* you get past the problems you are having with your code. We are not here as a code writing resource. Again, perhaps I am misreading your message. If so, my apologies. If not, try to find answers on your own first. Look at the documentation that comes with perl. Search the internet with Google. We help a lot of folks here, but we assume you have at least tried to solve things yourself. Take a look at the archives. Many of us that help very rarely ask questions here. I, for one, have learned how to answer most of my questions through research and by wasting my time and *not* asking here first. I'll bet a lot of programmers more experienced then me do the same. : PS: I see this term 'foo' 'bar' in many programming : books, what is the etymology of this? RFC 3092 - Etymology of Foo: http://www.faqs.org/rfcs/rfc3092.html BTW, this was the first link returned by Google. You could have at least tried to find it on your own. http://www.google.com/search?q=foo+etymology HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response Confidentiality Notice The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender at Wipro or [EMAIL PROTECTED] immediately and destroy all copies of this message and any attachments. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Program close
Anthony Vanelverdinghe wrote: Hi When I run a very simple Perl program, it closes immediately after it has done. So that I can't even see the output. How can I solve this? Thanks in advance! I take it you are running Windows? If so, you should be running Perl from the command prompt. In general, if you want to do serious work with the system, you should get used to working with the command prompt. There are a variety of other jobs for which no GUI tool is available. [OT but useful for Windows users] My suggestion: Open your Start Menu, then Programs, then Accessories. *Right-drag* the shortdut named MS-DOS Prompt [9x] or Command Prompt [Win2K or XP] either to the base of the start menu or to your desktop. Drop it and select Copy here from the context menu. You can also enter: cmd in the dialog that comes up with the Run... command on the start menu. Once selected, this command will become avaiable on the drop-down menu. If you find the black screen ugly, irritating, or intimidating, you can adjust the display colors by right-clicking the title bar of the command prompt, selecting Defaults, then, if necessary the Colors tab, and selecting the preferred background and foreground [text] colors. I have black type on an off-white background. The off-white shade differs just enough from other window backgrounds to make the command environment immediately recognizable. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: bad code, needs work...
LoneWolf wrote: Here's what I have, and I am sure there is a better way to do this... The problem I am getting is checking to see if one field matches the city, and if it does keeping it the same, however if it does not it needs to have a 1- added to the front of that field... I think the problem comes up right here. You are dscribing the problem in terms of details of the mechanism you think may work, rather than in terms of its logical description. Doing this handicaps your effort from the start. One field? Of what? What is it about that field that makes for a match? -- CODE -- #!/usr/bin/perl -w # # # Main Functions of the script, makes calls to all of the subscripts performing the functions. # Also creates pretty output for everyone to check out. This script is designed to run after WGEN has been run. # # no warnings qw(uninitialized); $content_type = Content-Type: text/html\n\n; print ENDPAGE; [EMAIL PROTECTED] html head titleCustomer Parsing Form/title body bgcolor=white text=black BR center CUSTOMER FILE DOWNLOAD AND CONFIGURE/center HR BR This will download and create the files onto the Intranet from Stanpak. Login to Stanpak FIRST and run ROBERT and ROBERT2 from *QICLOOK to create the files this script needs to handle the rest of this process.BR This should be at least three sentences. Not a Perl issue, you say? Think again. The above is meaningful only to someone who doesn't need to read it. All the user seeing this from the web should need to know is the end result. The details are your [the programmers] problem. Just as the above should be broken down into clear sentences, so should the problem itself. Please see Wiggins post concerning the code itself. Most of this should be done with loops, and probably a small data file to hold the names of all the files you are seeking to write. Can you try re-posing the problem de novo? Instead of describing programming structures, describe what you have for information coming in, and what you hope to come out with? You get there much faster when you know where you are headed. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array containment
Rob, James, James Edward Gray II wrote: On Feb 10, 2004, at 2:39 PM, Jan Eden wrote: Rob, I read the perlfaq paragraph you mentioned and found that it proposes a solution which does not make use of 'exists': What's wrong with exists()? I like exists() and you're going to hurt it's feelings. :) It has six characters which can be left out to minimize typing. You could also use map() I guess, if you don't consider that a loop: @[EMAIL PROTECTED] = map { 1 } 0..$#blues; For some irrational reason, I consider this more of a loop than your first/Rob's solution below. Rob Dixon wrote: It's not for me to rewrite the docs (or perhaps it is?) but for (@blues) { $is_blue{$_} = 1 } does the same thing as @[EMAIL PROTECTED] = (1) x @blues; I finally came up with an idea of my own, just when I got up this morning: @[EMAIL PROTECTED] = 1 .. @blues; This way each of the hash keys gets a value different from zero, so if ($is_blue{$_}) still works. Now it might be hard to determine which of these two is faster. There's really more than one way to do it. Thanks to you all, for patience and friendliness, Jan -- These are my principles and if you don't like them... well, I have others. - Groucho Marx -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Regarding Text Widget in Perl/Tk
Mike Flannigan wrote: I was wondering if you could help me get this script tied to one of my Perl programs on my Win2000 box. After much experimentation, I've changed the line open(C, ./read-own-stdout-piper 21 |) or warn $!; to open(C, round2.bat 21 |) or warn $!; round2.bat is a DOS batch file with a single line: perl round2.pl# (that is the way I run perl programs) round2.pl has: use strict; use warnings; my $number = 5.6278; my $rounded = sprintf '%.2f', $number; print $rounded\n; $|++; # SHOULD THIS LINE BE HERE? AND IT ALL WORKS! I can't just do open(C, round2.pl 21 |) or warn $!; because then it just opens round2.pl in my text editor, since that is the association I have .pl set to. Why?!?! Why screw with something that works, unscrewed with, just fine? The asscociations set up by the ActivePerl install are the appropriate ones for making Perl run. If you want associations to your preferred editor, then: Open Windows Explorer, or the abonminable kindergarten version My Computer Click Folder Options on the Tools menu Select File types Find the PL extension. Click the Advanced button. Restore the Open association with the perl executable. The Open action should read: C:\Perl\bin\perl.exe %1 %* presuming that Perl is installed to the default location for Windows Create an Edit action tied to your editor. Changing the primary association is a bad hack, and a bad habit to be in as you start learning a programming language. Actually, once you right-click on any registered file type in Win2K, and use the Open with... option option to select an alternate handler, that handler will thereafter be available on a list under the Open with menu item. In brief, there is no good reason to mess with a working file association I tried open(C, 'perl round2.pl' 21 |) or warn $!; but that didn't work either. open(C, perl round2.pl 21 |) or warn $!; or simply: open(CHILD, perl round2.pl | ) or warn Could not open pipe from child process: $!; That Got: prompt isn't too cool, but I'm sure I'll learn how to turn that off later. Also, it's unfortunate that copy and paste don't work in that TK box. If it is a Text widget, copy and paste will indeed work. Can you provide more detail on why you think it doesn't? Anyway, thanks a bunch. If there are other posts on the NG related to this, I'll see them when I get home. Mike Flannigan Houston, TX Mike, I think you have a conceptual problem here. Seeking STDIN from a GUI widget, hacking and breaking working file associations, etc. indicate a bad habit that will hobble your programming efforts if unaddressed. *Let working systems be*, don't fix what ain't broke. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl Documentation like Javadoc
Richard Heintze wrote: Speaking of documentaiton, is there any structured approach to documenting the get/post parameters for a perl web page? I have a main menu type of of page I have inherited. The GUI designer is not a programmer That is as it should be. GUI design should be focused on offering a natural experience to the user, and internal technical considerations should be secondary at that level of abstraction. That being said, multi-tier development projects do require clarity and the interfaces between tiers. seems to have a strong preference buttons instead of links or drop down menus. Can you explain what, in terms of information, is missing from the buttons that would show up in the links or menu items? What kind of information is being gathered here? What is the overall purpose of the system? Each push button represents another target page which has its own set of get/post parameters which require its own, sometimes conflicting, hidden HTML fields. The code is SO ugly because the previous programmers had no naming conventions and did not understand SQL. The question I see at this point is: What is the scope of the project? Are you doing a restructure of the system as a whole? If so, then I would suggest starting out by developing a Data Dictionary for the overall system. By doing this, you can ensure from the start that there is a common protocol and a common set of identifiers meaning the same thing throughout the system. Is there any structured approach to say: These hidden variables are for these destinatino pages. These are the get/post parameters for this page, etc...? and Here are the get/post params this page needs? This sounds like a question of system design. There are indeed a number of tools and conventions available to use in defining or describing a project and the role of each element in the context of the system as a whole. Unfortunately, you are not sharing the kind of detail that would help us steer you in the right direction for your needs. You seem more to be venting frustration--very understandable, but not immediately constructive. For what it's worth, Perl will function very well in handling CGI form input, no matter how bad the naming convention in the HTML may be. A string is just a string, to Perl. If you are not ready to, or in a position to, do a global restructure, I would advise doing a data dictionary for your own use, possibly with a table correlating the name and value strings of the HTML with the internal names of corresponding variables in your CGI layer. Although it can certainly be convenient to have the strings correspond across all layers of your system, it is by no means mandatory. You may have to just work with what you have. Javadoc won't even help me with this (if I was using Java). Siegfried Something you should understand about multi-tier systems--a large degree of independence between the layers is part of the plan. There should be clearly defined interfaces between the layers, definitely. Still, the internal structure of each layer should be focused on the needs of that layer. Tight coupling between the layers in a multitier processing system is likely to hobble each in performance of its work Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response