Re: Print statement
Hi, Is there any way in which I can tell perl where to print my data. i.e. Here is my .html That doesn't look like HTML to me? I am thoroughly confused, can you provide better information about the issue? As a hunch you might want to check out one of the various template kits, Template-Toolkit is a well respected one it seems, http://search.cpan.org/~abw/Template-Toolkit-2.13/ --- Header --- Body header in orig. place --- if ($var == 1) { bod_head = New Header - Override current body header; } else { bod_head = Body header in orig. place; } bod_head needs a sigil. 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
Switch
Is there some kind of a swtich statement in perl? -- Kind Regards, Werner Otto -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Switch
On 13 May 2004, at 10:29, Werner Otto wrote: Is there some kind of a swtich statement in perl? Yes and no. See: perldoc -q switch -- David Dorward http://dorward.me.uk/ http://blog.dorward.me.uk/ -- 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 Search for running Application
Hi All, Is there any way in perl i can search for the running application and its process id using perl. e.g. Let us suppose I know the name of the application as httpdbinary Can i search in processes whether that application is running and what is its process id My problem is even if some file with name httpd exists It will show you that also which i want to avoid. Please help Thanks, Generally this is handled best by the application itself generating a PID file. For instance if your httpd is Apache it will store a file (configurable) to a directory on the local filesystem that will store the initial process' PID. Then you don't need to read over the process table. Having said that, you might want to look at the documentation for Proc::ProcessTable, or I know drieux had some rants about this, do a google search for his homepage. HTH, 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: Incrementing during a regexp substitution
On May 13, Lee Johnson said: # # End date is a year after start date # $edate = $sdate; $edate =~ s/\///g; $edate++; $edate =~ s/.*(\d{4})$/01\/04\/$1/; Are you sure you want to just use April 1st (or January 4th) always? You don't want to use the day and month in $sdate? where $sdate is a UK date of the type dd/mm/ I've tried ($edate = $sdate) =~ s/(.*)(\d)$/$1($2++)/e; to no avail. I think I'm misunderstanding the /e modifier here? A little bit, yes. The /e modifier makes the right-hand side Perl code, and you should recognize that $1($2++) isn't valid Perl code. You'd need $1 . ($2++) but that won't work for two reasons. First, $x++ returns its OLD value, and THEN increments it, so you wouldn't get a changed value. The second reason is that you can't modify the $DIGIT variables. Finally, your code is making a mistake in the regex. What if the year is 2009? You're only matching the LAST digit of the year, and adding one to it. Your string would end up being ...20010, which is wrong. Match the whole four-digit year, and add one to it. When it rolls around to , then come back to me and complain about my bad code. ;) And your regex is doing more work than it has to. Why would you write s/(.*)(\d{4})$/$1 . (1 + $2)/e; when you could just write s/(\d{4})$/1 + $2/e; You're matching the WHOLE beginning of the string just to replace it with ITSELF. That's silly and inefficient. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Do this in one step (grab vars with s///)
How can I get var1 and var2 in one step using s/// type method? (Not using split) cat test.pl #!/usr/local/bin/perl -w $incoming = shift; ## Where incoming looks like '-A -a' ($var1 = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$2/; ($var2 = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$4/; print $var1\n$var2\n; ./test.pl '-A -a' A a I've tried various paran schemes to extract var1 and var2 in one step but only get errors.. example: (($var1, $var2) = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$2/; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
recording the position of m// searches
Hi, I am trying to build a perl program that reads through a very large text file, searches for a pattern, and prints the pattern - within its context - into a log file for later study. The context is defined as, say, 20 characters before and after the found pattern. I intend to use this for linguistic analysis. So I am thinking, use m//g to search, then push the found locations onto a list, then come back, printing out parts of the text file based on the search positions in the list, and use a context of 20 characters on either side. The pos() function within a m//g loop seems to return the position within the line, not the position within the file. Is there a different function to return the absolute position in the file, which I could then use later on as a basis for (very roughly) for each sort(@found_locations) print text from $position - 20 to $position +20 Thanks, Tim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: recording the position of m// searches
Two thoughts here: 1) The $. Variable has the line number of the file you are iterating through, so you could use that combined with pos() 2) You could also try something like this: while(INFILE){ if($_ =~ /.{20}$pattern.{20}/){ push(@found,$1); } } -Original Message- From: Tim Kylie Duke [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 12:17 AM To: Beginners perl Subject: recording the position of m// searches -snip So I am thinking, use m//g to search, then push the found locations onto a list, then come back, printing out parts of the text file based on the search positions in the list, and use a context of 20 characters on either side. The pos() function within a m//g loop seems to return the position within the line, not the position within the file. Is there a different function to return the absolute position in the file, which I could then use later on as a basis for (very roughly) for each sort(@found_locations) print text from $position - 20 to $position +20 -snip- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
tied variables
Hi !! Pls tell me what are the tied variables in perl. I have tried it to read it from book but some words from the experts will be quite useful to make further progress and clarity in understanding those in general terms. Thanks in advance, Regards, Anish _ Contact brides grooms FREE! http://www.shaadi.com/ptnr.php?ptnr=hmltag Only on www.shaadi.com. Register now! -- 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 using File::RsyncP module
Hello José, Unfortunatel -Message d'origine- De : NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED] Envoyé : mardi, 11. mai 2004 16:27 À : BERTHOLD Jean; [EMAIL PROTECTED] Objet : RE: Problem using File::RsyncP module -Original Message- From: BERTHOLD Jean [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 11, 2004 3:02 PM To: NYIMI Jose (BMB); [EMAIL PROTECTED] Cc: BERTHOLD Jean Subject: RE: Problem using File::RsyncP module Hello Jose, I tried: my $srcRep = /export/home/oracle/TEST-RSYNC/ ; $rs-remoteStart(0, '[EMAIL PROTECTED]::PWJA_arc'); Not sure but try it with an simpler directory name. Something like: $rs-remoteStart(0, 'oracle_udaipur_PWJA_arc'); Try also this: $rs-remoteStart(0, [EMAIL PROTECTED]::PWJA_arc} ); HTH, José. DISCLAIMER This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- 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 using File::RsyncP module
Hello José, Unfortunately, these different syntax don't work ... Perhaps I will ask directly to the module's author to find what is wrong in my code. Thanks again for your help ! Jean -Message d'origine- De : NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED] Envoyé : mardi, 11. mai 2004 16:27 À : BERTHOLD Jean; [EMAIL PROTECTED] Objet : RE: Problem using File::RsyncP module -Original Message- From: BERTHOLD Jean [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 11, 2004 3:02 PM To: NYIMI Jose (BMB); [EMAIL PROTECTED] Cc: BERTHOLD Jean Subject: RE: Problem using File::RsyncP module Hello Jose, I tried: my $srcRep = /export/home/oracle/TEST-RSYNC/ ; $rs-remoteStart(0, '[EMAIL PROTECTED]::PWJA_arc'); Not sure but try it with an simpler directory name. Something like: $rs-remoteStart(0, 'oracle_udaipur_PWJA_arc'); Try also this: $rs-remoteStart(0, [EMAIL PROTECTED]::PWJA_arc} ); HTH, José. DISCLAIMER This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: tied variables
On Thu, 2004-05-13 at 14:12, anish mehta wrote: Hi !! Pls tell me what are the tied variables in perl. I have tried it to read it from book but some words from the experts will be quite useful to make further progress and clarity in understanding those in general terms. By tying a variable you intercept all read/write accesses to a variable Now Assume You have a variable called $file_content and you can tie it ( using some scalar tie .. you can easily get docs ) to a file , say /tmp/foo , such a way that whenever you read the variable $file_content the content of /tmp/foo is read and whenever you update the the variable the file /tmp/foo is overwritten There are many ways you can use ties , the perl cookbook from oreilly has excellent examples Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Extracting attachment from mail
Hello, I need to write a perl script that will run on solaris and the job of this script will be : - read a mail from a predefined shared mail box (Outlook/Exchange Server) - extract the mail attachment (text file) - parse the content - create an excel sheet (same content) Any input is welcome ... José. DISCLAIMER This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent.
Re: Extracting attachment from mail
On Thu, 2004-05-13 at 14:52, NYIMI Jose (BMB) wrote: Hello, I need to write a perl script that will run on solaris and the job of this script will be : - read a mail from a predefined shared mail box (Outlook/Exchange Server) - extract the mail attachment (text file) - parse the content - create an excel sheet (same content) Any input is welcome ... José. perldoc MIME::Parser -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: WWW::Mechanize question
On Wed, May 12, 2004 at 12:59:44PM -0500, Ben Miller wrote: my @links = $mech-find_all_links(tag = a, text_regex = qr/\bWORD\b/i ); ... tag = a, ... I suspect. -- 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: Multi library
[EMAIL PROTECTED] wrote: my openconf function contains: sub openconf { my $pkg = shift; my $self = bless([EMAIL PROTECTED],$pkg); open(... return($self); } I have my @config; set at the beggining of the module you have defined @config as a class variable which means it will be shared among all instances of your My::Lib class. you don't want that, you need an instance variable instead. my $cfg1 = My::Lib-openconf(cfg1.conf); my $cfg2 = My::Lib-openconf(cfg2.conf); print $cfg1-param(someparam); print $cfg2-param(someparam); it prints two times the param from second conf file. Any ideas or I wasn't clear enough ?:) cfg1.conf and cfg2.conf both have the same param and because @config is shared among $cfg1 and $cfg2, they both print exactly the same thing. david -- s$s*$+/tgmecJntgRtgjvqpCvuwL$;$;=qq$ \x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65 \x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72 \x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32 \x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74 \x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$; -- 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 when sort file
John W. Krahn wrote: John Doe wrote: Hello all, Hello, i trying to sort one my file that is 10 MB and contain records: --- aa adsad dasd das aa --- i want to sort and eleminate double records. I use: $perl -0777ane '$, = \n; @[EMAIL PROTECTED] = (); print sort keys %uniq' \ out.log But i recive error: Out of memory! Yeah, this is normal, the file is 10 MB. Any body can help me ? You are reading the whole file into @F. Try doing it by reading one record at a time. perl -lne'$uniq{$_}++; END{print for sort keys %uniq}' out.log John This is work for files that is not so big 10 MB. But thanks. -- 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 when sort file
John McKown wrote: On Sun, 9 May 2004, John Doe wrote: Hello all, i trying to sort one my file that is 10 MB and contain records: --- aa adsad dasd das aa --- i want to sort and eleminate double records. I use: $perl -0777ane '$, = \n; @[EMAIL PROTECTED] = (); print sort keys %uniq' \ out.log But i recive error: Out of memory! Yeah, this is normal, the file is 10 MB. Any body can help me ? Regards, John John, What system? If you are on UNIX, I'd use the external sort command to sort my data, then use the uniq command. Much easier than using Perl, in my opinion. sort input.file | uniq output.file I can't help you if you are running under Windows. I don't think it has a sort or uniq command. If you need to process the records in Perl, I would most likely do: sort input.file | uniq | myPerlProgram.perl -- Maranatha! John McKown Thanks, this method is work great. Regards, John -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: dependency tree
Andrew Gaffney wrote: In a program I'm working on, I build a hash tree of sorts that contains package dependencies. Each key contains an array with the first level dependencies of the key. Each one of those dependencies have their own key with their first level dependencies in the hash. For example: my %tree = { package1 = [ package2, package3, package4 ], package2 = [ package7 ], package3 = [ package5 ], package4 = [ package7, package6], package5 = [ ], package6 = [ ], package7 = [ ] }; Now, I want to walk the tree starting with a known package1 and build an ordered list of packages to install. For example: package7 package2 package5 package3 (no package7 here because it is already in the list) package6 package4 package1 I also want to be able to track what package is a dependency of what (which key a certain value is under) with my tree structure. What is the easiest way to do this? Is there a better way to do this? Hi Andrew. Forgive the lack of explanation, I liked the challenge of this one and threw this together just before going to bed. I'll pick up any questions tomorrow. Just one thing, this will loop indefinitely if the dependencies are cyclic. Something like my %tree = ( package1 = [ qw/package2/ ], package2 = [ qw/package1/ ], ); But it's not hard to code for this case. Also, I'm not sure exactly how you want to 'track what package is a dependency of what'. If you just want a list of all packages that are dependent on a given package then that's fairly easy, but it should be done as a separate piece of code. HTH, Rob use strict; use warnings; use Data::Dumper; my %tree = ( package1 = [ qw/package2 package3 package4/ ], package2 = [ qw/package7/ ], package3 = [ qw/package5/ ], package4 = [ qw/package7 package6/ ], package5 = [ ], package6 = [ ], package7 = [ ] , ); my %remainder; my @install; @remainder{keys %tree} = (); while (keys %remainder ) { foreach my $package (keys %remainder) { my %dependencies; @[EMAIL PROTECTED] = (); delete @[EMAIL PROTECTED]; if (keys %dependencies == 0) { push @install, $package; delete $remainder{$package}; } } } print map $_\n, @install; **OUTPUT package5 package6 package7 package2 package3 package4 package1 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: dependency tree
Jeff 'Japhy' Pinyan wrote: my %tree = { package1 = [ package2, package3, package4 ], package2 = [ package7 ], package3 = [ package5 ], package4 = [ package7, package6], package5 = [ ], package6 = [ ], package7 = [ ] }; You have curly braces { ... } where you want parentheses ( ... ). Now, I want to walk the tree starting with a known package1 and build an ordered list of packages to install. For example: package7 package2 package5 package3 (no package7 here because it is already in the list) package6 package4 package1 This sounds like postorder tree traversal to me: // pseudocode postorder (tree) { if tree is null: return for node in tree.nodes: postorder(node) print tree } With your hash, in perl, this would look like: postorder(\%tree, 'package1'); sub postorder { my ($tree, $pkg, $seen) = @_; return if $seen-{$pkg}++; # to stop from traversing a node twice postorder($tree, $_, $seen) for @{ $tree-{$pkg} }; print $pkg\n; } This gives the expected output. Hi Jeff. But in the general caase there's a problem with finding the root of the tree. Indeed there may be several independent trees or none at all if the relationships are cyclic. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Finding missing numbers in sequence
I have a problem that I thought would be perfect for Perl, except that I seem to be using all my system resources to run it. Of course this probably means I'm doing it the wrong way... The problem: We have a backup server that is missing records from the production server for a particular table. We know that it should have sequential records and that it is missing some records. We want to get a sense of the number of records missing. So, we know the problem started around the beginning of March at id 70,000,000 (rounded for convenience). Currently we are at 79,000,000. So, I dumped to a file all the ids between 70,000,000 and 79,000,000 (commas inserted here for readability). I need to figure out what numbers are missing. The way that seemed easiest to me was to create two arrays. One with every number between 70 and 79 million, the other with every number in our dump file. Then compare them as illustrated in the Perl Cookbook using a hash. The simple script I came up with works fine with a test file of just 10 records. But, when I try to scale that to 9 million records, it doesn't work. This is probably because it is trying to do something like what db people call a cartesian join (every record against every record). So, does anybody have a suggestion for a better way to do it in Perl? I'll probably end up doing it in SQL if I can't come up with a Perl solution. (Create a second table like the first array with every number between 70 and 79 million, and join the two tables.) Larry [EMAIL PROTECTED] script: use strict; use warnings; my %seen; my @list = (); my @missing; my @ids = (); my $lis; my $item; foreach $lis (1 .. 10) { # sample list of 10 push(@ids, $lis); } open(DATA, ms_ids_test.txt) or die Couldn't open data file: $!\n; # create file like below while (DATA) { chomp; push(@list, $_); } @[EMAIL PROTECTED] = (); foreach $item (@ids) { push(@missing, $item) unless exists $seen{$item}; } print scalar(@missing); #sample file (without the pounds) #1 #2 #3 #4 #5 #9 #10 # note missing 6,7,8 # result is 3
Re: Finding missing numbers in sequence
I think there will be some optimizations always possible, but You wont get any dramatic improvements. What I would do is something like this First make sure that all the data is sorted in the file Create a sequence array of all the required numbers, In your example it was all numbers from 1..10 #!/usr/bin/perl # # my @full_sequence = (1..10); my @missing=(); my $i=0; while(DATA){ chomp; while($full_sequence[$i] != $_) { push @missing , $full_sequence[$i++] ; } $i++ } print MISSING ARE @missing\n; exit 0; ___ END__ Just try that out , hope it will be better. Infact your requirement is very data specific , It will hardly make any difference wether you code in PERL or in C Bye Ram On Thu, 2004-05-13 at 04:09, Larry Wissink wrote: I have a problem that I thought would be perfect for Perl, except that I seem to be using all my system resources to run it. Of course this probably means I'm doing it the wrong way... The problem: We have a backup server that is missing records from the production server for a particular table. We know that it should have sequential records and that it is missing some records. We want to get a sense of the number of records missing. So, we know the problem started around the beginning of March at id 70,000,000 (rounded for convenience). Currently we are at 79,000,000. So, I dumped to a file all the ids between 70,000,000 and 79,000,000 (commas inserted here for readability). I need to figure out what numbers are missing. The way that seemed easiest to me was to create two arrays. One with every number between 70 and 79 million, the other with every number in our dump file. Then compare them as illustrated in the Perl Cookbook using a hash. The simple script I came up with works fine with a test file of just 10 records. But, when I try to scale that to 9 million records, it doesn't work. This is probably because it is trying to do something like what db people call a cartesian join (every record against every record). So, does anybody have a suggestion for a better way to do it in Perl? I'll probably end up doing it in SQL if I can't come up with a Perl solution. (Create a second table like the first array with every number between 70 and 79 million, and join the two tables.) Larry [EMAIL PROTECTED] script: use strict; use warnings; my %seen; my @list = (); my @missing; my @ids = (); my $lis; my $item; foreach $lis (1 .. 10) { # sample list of 10 push(@ids, $lis); } open(DATA, ms_ids_test.txt) or die Couldn't open data file: $!\n; # create file like below while (DATA) { chomp; push(@list, $_); } @[EMAIL PROTECTED] = (); foreach $item (@ids) { push(@missing, $item) unless exists $seen{$item}; } print scalar(@missing); #sample file (without the pounds) #1 #2 #3 #4 #5 #9 #10 # note missing 6,7,8 # result is 3 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: dependency tree
On May 12, Rob Dixon said: Now, I want to walk the tree starting with a known package1 and build an ordered list of packages to install. For example: But in the general caase there's a problem with finding the root of the tree. Indeed there may be several independent trees or none at all if the relationships are cyclic. Well, the OP said he wanted to start with a specific package, so it sounds like he knows that will be the root of the tree. In addition, I don't expect it's proper form for a dependency tree to be cyclic... that would be impossible to work with, realistically speaking. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: tied variables
On May 13, anish mehta said: Pls tell me what are the tied variables in perl. I have tried it to read it from book but some words from the experts will be quite useful to make further progress and clarity in understanding those in general terms. A tied variable can be explained in two ways; I don't know which will be easier for you to understand. First, a tied variable is an object (as in object-oriented programming) that looks and behaves like a regular Perl data structure: a scalar, an array, or a hash. tie my($foo), 'Some::Scalar::Thing'; $foo = 3; print $foo; is the same as my $foo_object = Some::Scalar::Thing-TIESCALAR; $foo_object-STORE(3); print $foo_object-FETCH(); If you're familiar with OOP, the 'TIESCALAR' method is analogous to the usual 'new' method -- it creates the object. When you tie a variable, though, the object is hidden from the interface: you use a normal Perl variable that is hooked to an object. The other way to explain it is that a tied variable is a variable that you can intercept ALL accesses to. As shown above, there are functions called (Some::Scalar::Thing::STORE and Some::Scalar::Thing::FETCH) whenever a tied scalar is given a value or requested its value. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to Search for running Application
Hi All, Is there any way in perl i can search for the running application and its process id using perl. e.g. Let us suppose I know the name of the application as httpdbinary Can i search in processes whether that application is running and what is its process id My problem is even if some file with name httpd exists It will show you that also which i want to avoid. Please help Thanks, - Do you Yahoo!? Yahoo! Movies - Buy advance tickets for 'Shrek 2'
Re: recording the position of m// searches
On May 13, Tim Kylie Duke said: I am trying to build a perl program that reads through a very large text file, searches for a pattern, and prints the pattern - within its context - into a log file for later study. The context is defined as, say, 20 characters before and after the found pattern. I intend to use this for linguistic analysis. You're creating a program that creates a concordance, right? The pos() function within a m//g loop seems to return the position within the line, not the position within the file. Is there a different function to return the absolute position in the file, which I could then use later on as a basis for Well, here's one way to do it. It uses some concepts you might not yet be familiar with, so I'll stop the code and explain it as we go along: open FILE, file.txt or die can't read file.txt: $!; while (FILE) { my $orig_file_pos = tell FILE; my $line_start = $orig_file_pos - length($_); The tell() function returns the position in the filehandle. We need this because, after we get a match, we're going to do some jumping around in the file to extract the 20 pre- and 20 post-characters, and we want to be able to go back to where we SHOULD be when all the work is done. Then, we subtract the length of this line FROM that value, and put that into $line_start. After we've read a line, tell() is the position in the file RIGHT AFTER that line. We also need to know the position at the BEGINNING of that line, and you'll see why soon: while (/pattern/g) { my $chunk = ; my $match_start = $-[0]; my $match_length = $+[0] - $-[0]; Ok, $-[0] is the first element of the @- array. Assuming you're using AT LEAST Perl 5.6, you have this array. After a successful regex match, the @- and @+ arrays are populated with the offsets of the capture groups in the string you matched. Here's an example: japhy =~ /a((.).)/; # $: $-[0] is 1$+[0] is 4 # $1: $-[1] is 2$+[1] is 4 # $2: $-[2] is 2$+[2] is 3 Basically, it says that $1 is from position 2 to position 4 in the string we matched (japhy), and that $2 is from position 2 to position 3. $-[0] and $+[0] allow us to access the whole match ($) without having to use the evil $ variable (which causes slowdowns for all regexes in your code). (See 'perldoc perlvar' for more details.) As you can see from my small example above, $+[$N] - $-[$N] returns the length of the capture group. In our case, $+[0] - $-[0] returns the length of the entire match. seek(FILE, $line_start + $match_start - 20, 0); This brings us to 20 characters BEFORE the start of the match (regardless of what line that puts us on). The arguments to seek() are the filehandle, the offset (where in the file to go), and a third argument that defines how to use this offset. (If you wanted to go 10 characters back from your current position, you would do seek(FILE, -10, 1), and if you wanted to go 10 characters forward from your current position, you'd do seek(FILE, 10, 1).) In this case, the argument '0' means relative to the beginning of the file. read(FILE, $chunk, 20 + $match_length + 20); Here, we read $match_length + 40 characters into $chunk. Simple enough. # if you want to turn newlines into literal \n symbols, do this: $chunk =~ s/\n/\\n/g; That's just in case you don't want to display multi-line chunks as multiple lines, but just as containing newlines. Now, we print: print FOUND: [$chunk]\n; } seek(FILE, $orig_file_pos, 0); Once we're done finding matches on this line, we want to go back to where we were before, IMMEDIATELY after this line. This will allow FILE to read the next line properly. } close FILE; Here's the code, uninterrupted: open FILE, file.txt or die can't read file.txt: $!; while (FILE) { my $orig_file_pos = tell FILE; my $line_start = $orig_file_pos - length($_); while (/pattern/g) { my $chunk = ; my $match_start = $-[0]; my $match_length = $+[0] - $-[0]; seek(FILE, $line_start + $match_start - 20, 0); read(FILE, $chunk, 20 + $match_length + 20); $chunk =~ s/\n/\\n/g; # turn \n into literal \ n print FOUND: [$chunk]\n; } seek(FILE, $orig_file_pos, 0); } close FILE; And there you go. There are other ways to do this, of course. One way would be to see if the current line has enough characters on it that we can just do a substr() on it, and not move around in the file, but I think that's too much thinking and work for this task right now, and that this is more straightforward. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL
Re: Finding missing numbers in sequence
- Original Message - From: Larry Wissink [EMAIL PROTECTED] Newsgroups: perl.beginners To: [EMAIL PROTECTED] Sent: Wednesday, May 12, 2004 6:39 PM Subject: Finding missing numbers in sequence I have a problem that I thought would be perfect for Perl, except that I seem to be using all my system resources to run it. Of course this probably means I'm doing it the wrong way... The problem: We have a backup server that is missing records from the production server for a particular table. We know that it should have sequential records and that it is missing some records. We want to get a sense of the number of records missing. So, we know the problem started around the beginning of March at id 70,000,000 (rounded for convenience). Currently we are at 79,000,000. So, I dumped to a file all the ids between 70,000,000 and 79,000,000 (commas inserted here for readability). I need to figure out what numbers are missing. The way that seemed easiest to me was to create two arrays. One with every number between 70 and 79 million, the other with every number in our dump file. Then compare them as illustrated in the Perl Cookbook using a hash. So, does anybody have a suggestion for a better way to do it in Perl? Hello Larry, I was able to come up with a simple script that doesn't require using an array/hash, so that your mem problems should not occur. NOTE: the beginning number has to have 1 subtracted from it. This is a first case situation so that that the algorithm works for the set. Also, if there are missing records after the last number read in, it won't find that sequence, but that should be easy enough to find (in this example, any numbers after 20). HTH Chris #!/usr/bin/perl use strict; use warnings; my @missing; my $i = 0; # Or 70,000,000 - 1 (69,999,999) while(DATA) { if ($_ != ++$i) { push @missing, $i .. $_ - 1; $i = $_; } } print join \n, @missing; __DATA__ 4 5 7 10 12 13 14 15 20 OUTPUT 1 2 3 6 8 9 11 16 17 18 19 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Finding missing numbers in sequence
On May 12, Larry Wissink said: We have a backup server that is missing records from the production server for a particular table. We know that it should have sequential records and that it is missing some records. We want to get a sense of the number of records missing. So, we know the problem started around the beginning of March at id 70,000,000 (rounded for convenience). Currently we are at 79,000,000. So, I dumped to a file all the ids between 70,000,000 and 79,000,000 (commas inserted here for readability). I need to figure out what numbers are missing. The way that seemed easiest to me was to create two arrays. One with every number between 70 and 79 million, the other with every number in our dump file. Then compare them as illustrated in the Perl Cookbook using a hash. But, when I try to scale that to 9 million records, it doesn't work. This is probably because it is trying to do something like what db people call a cartesian join (every record against every record). Well, don't do that! ;) When you have a super-set and a sub-set, and they're ordered, you only need to go through the set ONCE. @superset = (1 .. 10); @subset = (1, 2, 4, 7, 8, 9); @missing = (); my $idx = 0; for (@superset) { push @missing, $_ unless $subset[$idx] == $_ and ++$idx; } That's just a bit of shorthand for: for (@superset) { if ($subset[$idx] == $_) { $idx++ } else { push @missing, $_ } } Anyway, that populates @missing with the missing elements, in linear time. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- 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::Optomizer
JupiterHost.Net wrote: Hello list, Perl::Tidy is very excellent for making source look nice. I was wondering if anyone knew of anything that is the same type of idea but it optomizes your Perl code to run a bit faster: for instance: $newvariable = $howdy; should be: $newvariable = $howdy; That's not an appropriate optimization. Perl objects can overload stringification. ... $str = CGI::header() . hello . $v; woudl become $str = CGI::header(),hello, $v; That's not equivalent code at all. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Incrementing during a regexp substitution
Is there a faster and/or cleaner way to do the following: # # End date is a year after start date # $edate = $sdate; $edate =~ s/\///g; $edate++; $edate =~ s/.*(\d{4})$/01\/04\/$1/; where $sdate is a UK date of the type dd/mm/ I've tried ($edate = $sdate) =~ s/(.*)(\d)$/$1($2++)/e; to no avail. I think I'm misunderstanding the /e modifier here? Cheers, Lee -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Extracting attachment from mail
NYIMI Jose (BMB) wrote: I need to write a perl script that will run on solaris and the job of this script will be : - read a mail from a predefined shared mail box (Outlook/Exchange Server) Mail::IMAPClient or Mail::POP3Client - extract the mail attachment (text file) - parse the content MIME::Parser - create an excel sheet (same content) Spreadsheet::WriteExcel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Extracting attachment from mail
NYIMI Jose (BMB) wrote: I need to write a perl script that will run on solaris and the job of this script will be : - read a mail from a predefined shared mail box (Outlook/Exchange Server) Mail::IMAPClient or Mail::POP3Client - extract the mail attachment (text file) - parse the content MIME::Parser While were listing modules ;-), I will throw in Mail::Box, since it is one distro that should be able to do both the accessing and parsing. 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::Optomizer
* JupiterHost.Net [EMAIL PROTECTED] [2004-05-13T11:35:58] Bob Showalter wrote: for instance: $newvariable = $howdy; should be: $newvariable = $howdy; That's not an appropriate optimization. Perl objects can overload stringification. Interesting... So when would that cause problems? If $howdy is an object that returns Hello! when turned into a string, then the first bit of code assigns Hello! to $newvariables. The second bit of code makes $newvariable a copy of $howdy. $str = CGI::header() . hello . $v; woudl become $str = CGI::header(),hello, $v; That's not equivalent code at all. I didn't think so but I read somewhere to use commas instead of concatenation with periods. I always thought the commas was a bit different but if you print $str; they are the samem in each example. Look at the prototype for Cprint. It takes a LIST, and those elements are concatted together and printed. (see perldoc -f print) The value of $, is stuck between list elements, but it's usually empty. So, Cprint $foo, $bar is mostly equivalent to Cprint $foo . $bar in usual circumstances, but C$foo = $bar, $baz is wildly different from C$foo = $bar . $baz; the first sets foo to baz. The second sets it to bar and baz concatenated. I'm sure I have much to learn as far as the period/comma thing go :) When in doubt, look in perldoc. About comma, it says: Binary , is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C's comma operator. What I'm really looking for is a similar thing to Perl::Tidy that I can run a script throught and have it make an optomized version. You mean optimized. That would be complex but wouldn't it be cool? I can't imagine wanting to use it; it would take time to run, and I don't think I would trust it. Perl is fast enough for me. Better to learn how to write fast-enough code to begin with, imho. -- rjbs pgp0.pgp Description: PGP signature
RE : Extracting attachment from mail
-Message d'origine- De : Wiggins d Anconia [mailto:[EMAIL PROTECTED] Envoyé : jeudi 13 mai 2004 18:02 À : NYIMI Jose (BMB); [EMAIL PROTECTED] Objet : RE: Extracting attachment from mail -Original Message- From: NYIMI Jose (BMB) Sent: Thursday, May 13, 2004 11:23 AM To: [EMAIL PROTECTED] Subject: Extracting attachment from mail Hello, I need to write a perl script that will run on solaris and the job of this script will be : - read a mail from a predefined shared mail box (Outlook/Exchange Server) - extract the mail attachment (text file) - parse the content - create an excel sheet (same content) Any input is welcome ... José. One more info about the flow: * the original mail comes from an external user (outside our company): no problem to that ... * a MS Outlook rule will be set to forward this mail (with attachment) to an unix user (solaris): good ? * mails received by this unix user are all stored in the file named /var/mail/username * a perl script will be scheduled once per day to: It sounds like you have a fair amount of control. Out of curiousity have you considered having an alias established on the solaris box that rather than dumps the message to a mail box, instead pipes it to a program (aka your perl program). That program can then parse the message directly on STDIN. This cuts out the need for the scheduler, cleaning up the mail folder (since the message is handled directly and then discarded (if desired)), and allows the file to be handled closer to real time. Nice! I will investigate on that. José. -- 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::Optomizer
Ricardo SIGNES wrote: * JupiterHost.Net [EMAIL PROTECTED] [2004-05-13T11:35:58] Bob Showalter wrote: for instance: $newvariable = $howdy; should be: $newvariable = $howdy; That's not an appropriate optimization. Perl objects can overload stringification. Interesting... So when would that cause problems? If $howdy is an object that returns Hello! when turned into a string, then the first bit of code assigns Hello! to $newvariables. The second bit of code makes $newvariable a copy of $howdy. I see... $str = CGI::header() . hello . $v; woudl become $str = CGI::header(),hello, $v; That's not equivalent code at all. I didn't think so but I read somewhere to use commas instead of concatenation with periods. I always thought the commas was a bit different but if you print $str; they are the samem in each example. Look at the prototype for Cprint. It takes a LIST, and those elements are concatted together and printed. (see perldoc -f print) The value of $, is stuck between list elements, but it's usually empty. So, Cprint $foo, $bar is mostly equivalent to Cprint $foo . $bar in usual circumstances, but C$foo = $bar, $baz is wildly different from C$foo = $bar . $baz; the first sets foo to baz. The second sets it to bar and baz concatenated. I'm sure I have much to learn as far as the period/comma thing go :) When in doubt, look in perldoc. About comma, it says: Binary , is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C's comma operator. What I'm really looking for is a similar thing to Perl::Tidy that I can run a script throught and have it make an optomized version. You mean optimized. :) Now I need a spell checker :) That would be complex but wouldn't it be cool? I can't imagine wanting to use it; it would take time to run, and I don't think I would trust it. Perl is fast enough for me. Better to learn how to write fast-enough code to begin with, imho. You wouldn't use it at runtime, you'd run your code through it and getr anew file with slicker code then use that in your normal use. But I agree better to learn and use the most efficient code :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Incrementing during a regexp substitution
Jeff 'Japhy' Pinyan wrote: On May 13, Lee Johnson said: # # End date is a year after start date # $edate = $sdate; $edate =~ s/\///g; $edate++; $edate =~ s/.*(\d{4})$/01\/04\/$1/; Are you sure you want to just use April 1st (or January 4th) always? You don't want to use the day and month in $sdate? where $sdate is a UK date of the type dd/mm/ I've tried ($edate = $sdate) =~ s/(.*)(\d)$/$1($2++)/e; to no avail. I think I'm misunderstanding the /e modifier here? A little bit, yes. The /e modifier makes the right-hand side Perl code, and you should recognize that $1($2++) isn't valid Perl code. You'd need $1 . ($2++) but that won't work for two reasons. First, $x++ returns its OLD value, and THEN increments it, so you wouldn't get a changed value. The second reason is that you can't modify the $DIGIT variables. Finally, your code is making a mistake in the regex. What if the year is 2009? You're only matching the LAST digit of the year, and adding one to it. Your string would end up being ...20010, which is wrong. Match the whole four-digit year, and add one to it. When it rolls around to , then come back to me and complain about my bad code. ;) Also, if the current date is 29/02/2004 and you increment the year to 2005... 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
date manipulation mods
Group, Is there a date manipulation module that does the same thing as gnu `date -d' command? That is, given a spec string, it returns a date in the past in user selected format. Like what gnu `date' would do with: date -d '-2 weeks' +%m%d%Y_%T 04292004_13:20:28 I've written some manipulations using `time' and `localtime' plus `printf' but doing the above is quite a lot more complex. -- 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 mods
On May 13, Harry Putnam said: Is there a date manipulation module that does the same thing as gnu `date -d' command? That is, given a spec string, it returns a date in the past in user selected format. Like what gnu `date' would do with: date -d '-2 weeks' +%m%d%Y_%T 04292004_13:20:28 You can use the standard (i.e. comes with Perl) POSIX module. It has a strftime() function that behaves like C's does. Read the man page for strftime and you'll have a pretty good idea how to use POSIX::strftime(). use POSIX 'strftime'; my $date = strftime format string, localtime; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Do this in one step (grab vars with s///)
Harry Putnam wrote: How can I get var1 and var2 in one step using s/// type method? (Not using split) cat test.pl #!/usr/local/bin/perl -w $incoming = shift; ## Where incoming looks like '-A -a' ($var1 = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$2/; ($var2 = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$4/; print $var1\n$var2\n; ./test.pl '-A -a' A a I've tried various paran schemes to extract var1 and var2 in one step but only get errors.. example: (($var1, $var2) = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$2/; $incoming =~ s/^( *-)([A-Z])( *-)([a-z])/($var1, $var2)=($2,$4)/e; 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: How to Search for running Application
Wiggins d Anconia [EMAIL PROTECTED] writes: Hi All, Is there any way in perl i can search for the running application and its process id using perl. e.g. Let us suppose I know the name of the application as httpdbinary Can i search in processes whether that application is running and what is its process id My problem is even if some file with name httpd exists It will show you that also which i want to avoid. Please help [...] maybe missing your point.. But if this is on unix/unixlike OS and doesn't demand portablility, you could resort to a system or qx call to `ps wwaux' if one of the bsd styles or whatever system V ps -??? (not sure what it is) But maybe thats not accessable -- 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 mods
Harry Putnam wrote: Group, Is there a date manipulation module that does the same thing as gnu `date -d' command? That is, given a spec string, it returns a date in the past in user selected format. Like what gnu `date' would do with: date -d '-2 weeks' +%m%d%Y_%T 04292004_13:20:28 I've written some manipulations using `time' and `localtime' plus `printf' but doing the above is quite a lot more complex. Like Jeff said, POSIX::strftime will help with the formatting. For offsetting 2 weeks, you can do the simple: time - 14 * 86_400 Or, you can use something like Date::Manip which handles the '2 weeks ago' type of expressions. It has its own UnixDate function that is similar to POSIX::strftime. -- 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 mods
Jeff 'japhy' Pinyan [EMAIL PROTECTED] writes: On May 13, Harry Putnam said: Is there a date manipulation module that does the same thing as gnu `date -d' command? That is, given a spec string, it returns a date in the past in user selected format. Like what gnu `date' would do with: date -d '-2 weeks' +%m%d%Y_%T 04292004_13:20:28 You can use the standard (i.e. comes with Perl) POSIX module. It has a strftime() function that behaves like C's does. Read the man page for strftime and you'll have a pretty good idea how to use POSIX::strftime(). use POSIX 'strftime'; my $date = strftime format string, localtime; My question was regarding getting dates in past... Maybe I'm overlooking something obvious but a cruise thru `man strftime' hasn't unearthed a method to get past dates like gnu `date -d' can do. Ditto for perldoc POSIX -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
perldoc display with data missing
My setup: OS= Linux (FedoraCore1 test2) I see an actual loss of data in reading perldoc output from an xterm if my term is sized a little small. I'll show a repeatable example (here anyway): xterm -geometry 65x20 In that xterm call: perldoc POSIX In that page search for past (/past ENTER) The hit shows up above the visable page and much of the line is just missing. Not just scambled but actually missing. You can see the missing data by calling: perldoc POSIX file less file then search for /past again Or perldoc POSIX in an 85x30 xterm. My term is xterm and LANG is en_US.UTF-8 I don't think was a problem in the recent past as I've used undersized xterms for years. -- 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 mods
Bob Showalter [EMAIL PROTECTED] writes: Or, you can use something like Date::Manip which handles the '2 weeks ago' type of expressions. It has its own UnixDate function that is similar to POSIX::strftime. Aha... now we're talking. Date::Manip is what I was after: cat test.pl: #!/usr/local/bin/perl -w use Date::Manip; print UnixDate((DateCalc(now,-3weeks)),%m%d%Y_%T). \n; There is probably even a simpler formulation. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Do this in one step (grab vars with s///)
John W. Krahn [EMAIL PROTECTED] writes: (($var1, $var2) = $incoming) =~ s/(^ *\-)([A-Z])( *\-)([a-z])/$2/; $incoming =~ s/^( *-)([A-Z])( *-)([a-z])/($var1, $var2)=($2,$4)/e; Ha.. yup thats right, you can put an expression between those last two slashes... nice. -- 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::Optomizer
Jeff 'japhy' Pinyan wrote: The lesson to learn is: Premature optimization is the root of all evil. Got ya ;p http://en.wikipedia.org/wiki/Optimization_(computer_science) Optimization (computer science From Wikipedia, the free encyclopedia. (Wikipedia does not have an article on this topic yet. To start the article, click Edit this page.) ?? :( I was wanting to read it... -- 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::Optomizer
http://en.wikipedia.org/wiki/Optimization_(computer_science) Optimization (computer science From Wikipedia, the free encyclopedia. (Wikipedia does not have an article on this topic yet. To start the article, click Edit this page.) ?? :( I was wanting to read it... Looks like your e-mail program passed the link to your browser without the closing parenthesis. (look at the title, it's missing the closing parenthesis that was present in the link) Copy an paste the link into your browser, and you should get the right page, as I did. J-S ___ Jean-Sébastien Guay [EMAIL PROTECTED] http://whitestar02.webhop.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: date manipulation mods
On May 13, Harry Putnam said: Jeff 'japhy' Pinyan [EMAIL PROTECTED] writes: On May 13, Harry Putnam said: Is there a date manipulation module that does the same thing as gnu `date -d' command? That is, given a spec string, it returns a date in the past in user selected format. Like what gnu `date' would do with: date -d '-2 weeks' +%m%d%Y_%T 04292004_13:20:28 You can use the standard (i.e. comes with Perl) POSIX module. It has a strftime() function that behaves like C's does. Read the man page for strftime and you'll have a pretty good idea how to use POSIX::strftime(). use POSIX 'strftime'; my $date = strftime format string, localtime; My question was regarding getting dates in past... Maybe I'm overlooking something obvious but a cruise thru `man strftime' hasn't unearthed a method to get past dates like gnu `date -d' can do. I'm sorry, I misread the question. I thought you were asking about the FORMATTING of the date (the %m%d%Y_%T part) not the time travel part. ;) Date::Manip is A+ for that. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- 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::Optomizer
Jean-Sébastien Guay wrote: http://en.wikipedia.org/wiki/Optimization_(computer_science) Optimization (computer science From Wikipedia, the free encyclopedia. (Wikipedia does not have an article on this topic yet. To start the article, click Edit this page.) ?? :( I was wanting to read it... Looks like your e-mail program passed the link to your browser without the closing parenthesis. (look at the title, it's missing the closing parenthesis that was present in the link) Copy an paste the link into your browser, and you should get the right page, as I did. Der! Thanks :) J-S ___ Jean-Sébastien Guay [EMAIL PROTECTED] http://whitestar02.webhop.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
check my split
Hello, This code below works. But I am wondering if it can be made more efficient: while (FHOREAD) { my $sport = (split(/\s/,$_))[8]; my $sdport = (split(/\s/,$_))[10]; next if $sport =~ /\D/; next if $dport =~ /\D/; if ($sport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/ || $dport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ } else { print FHODATA} } print RFHODATA @rest; } 8 and 10 are numbers 80,5000,53, etc.. will print if 8 0r 10 match my list to one file and it if dosen't match print to another file. I looked at doing something like this but no good: while (FHOREAD) { my $sdport = (split(/\s/,$_))[8],[10]; next if $sdport =~ /\D/; if ($sdport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ } else { print FHODATA} } print RFHODATA @rest; Thanks 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: check my split
rmck wrote: Hello, This code below works. But I am wondering if it can be made more efficient: while (FHOREAD) { my $sport = (split(/\s/,$_))[8]; my $sdport = (split(/\s/,$_))[10]; next if $sport =~ /\D/; next if $dport =~ /\D/; if ($sport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/ || $dport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ } else { print FHODATA} } print RFHODATA @rest; } 8 and 10 are numbers 80,5000,53, etc.. will print if 8 0r 10 match my list to one file and it if dosen't match print to another file. I looked at doing something like this but no good: while (FHOREAD) { my $sdport = (split(/\s/,$_))[8],[10]; This I think is unclear, what were you trying to do with the above? next if $sdport =~ /\D/; if ($sdport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ } else { print FHODATA} } print RFHODATA @rest; As for making it more efficient, a hunch tells me it would be more efficient to use grep on your list rather than a regex with lots of alternation, however Perl/regex has some pretty cool optimizations so using Benchmark would be the best way to tell. I would think something along the lines of my @ports = (20,21,22,25,53,80,109,110,123,137,161,443); if ((grep $sport == $_, @ports) || (grep $dport == $_, @ports)) { } Or even so that we only need a single loop, if (grep { $sport == $_ or $dport == $_ } @ports) { } HTH, 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: check my split
On May 13, rmck said: while (FHOREAD) { my $sport = (split(/\s/,$_))[8]; my $sdport = (split(/\s/,$_))[10]; You have $sdport here, but you USE $dport. next if $sport =~ /\D/; next if $dport =~ /\D/; if ($sport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/ || $dport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ } else { print FHODATA} } print RFHODATA @rest; I'd probably do: # set up valid values for $sport and $dport my %ok; @ok{20,21,22,25,53,80,109,110,123,137,161,443} = (); while (FHOREAD) { my ($sport, $dport) = (split)[8, 10]; next if $sport =~ /\D/ or $dport =~ /\D/; if (exists $ok{$sport} or exists $ok{$dport}) { push @rest, $_ } else { print FHODATA } } -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN[Need a programmer? If you like my work, let me know.] stu what does y/// stand for? tenderpuss why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
CGI.pm / Upload File / delete temporary file (CGITemp****)
Hi All, Been ages since I last posted to this list... Anyhoo, I have a script which handles the uploading of a file. It uses the CGI module to get the form params etc and open/read/close statements to receive the file. This is fine and all works well. The problem is a temporary file (of the same size as the uploaded file) is created in the TEMP directory. It has a name along the lines of 'CGITemp' where the asterisks represent a sequence number. Is there any switch/arg to prevent this or at least delete this file when the upload is completed? I have googled to no avail. I suppose I could just delete it myself but I don't know the CGITemp sequence number. If no one knows I guess i'll have to have a look at the code for CGI.pm :( I'm on Win32, perl v5.6.1, CGI v2.752 Thanks Toby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response