[30056] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1299 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 22 16:09:54 2008

Date: Fri, 22 Feb 2008 13:09:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 22 Feb 2008     Volume: 11 Number: 1299

Today's topics:
    Re: bash and perl <dw149@acmex.gatech.edu>
        BEGIN not safe after errors--compilation aborted <darrenbird@dipinternational.co.uk>
    Re: BEGIN not safe after errors--compilation aborted <glex_no-spam@qwest-spam-no.invalid>
    Re: Broken links in Activestate Perl distribution <someone@example.com>
        glob a directory then sort by timestamp jhellma1@gmail.com
    Re: glob a directory then sort by timestamp <jurgenex@hotmail.com>
        Intention to take over Finance::Bank::Cahoot <ciamabue@googlemail.com>
    Re: Long line in perl script <ced@blv-sam-01.ca.boeing.com>
    Re: MAKE MONEY FAST USING EGOLD!! dummy@phony.info
    Re: setting %ENV in a module <pgodfrin@gmail.com>
    Re: setting %ENV in a module <jimsgibson@gmail.com>
    Re: setting %ENV in a module <ben@morrow.me.uk>
        Speeding my script <phynkel@gmail.com>
    Re: Speeding my script <smallpond@juno.com>
    Re: Speeding my script <christian.hansel@cpi-service.com>
    Re: Speeding my script <glex_no-spam@qwest-spam-no.invalid>
        Split a string in perl <chunji08@gmail.com>
    Re: Split a string in perl <ced@blv-sam-01.ca.boeing.com>
    Re: Split a string in perl <jimsgibson@gmail.com>
    Re: Split a string in perl dummy@phony.info
    Re: Split a string in perl <ben@morrow.me.uk>
    Re: Split a string in perl <chunji08@gmail.com>
    Re: Split a string in perl <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 22 Feb 2008 14:53:16 +0000 (UTC)
From: David Williams <dw149@acmex.gatech.edu>
Subject: Re: bash and perl
Message-Id: <fpmnks$7me$1@news-int2.gatech.edu>

Okay.
Sorry to everyone.  Apparently, I can just open up
sendmail directly from perl like

open(filedesc,"| 'path to sendmail' -t");
sendmail headers
 .
 .
 .
 .

close filedesc;


Sorry for all of the confusion 



-- 
David Williams
Georgia Institute of Technology, Atlanta Georgia, 30332
Email: dw149@prism.gatech.edu


------------------------------

Date: Fri, 22 Feb 2008 08:26:28 -0800 (PST)
From: daz9643 <darrenbird@dipinternational.co.uk>
Subject: BEGIN not safe after errors--compilation aborted
Message-Id: <842d7aad-e832-498a-8a5c-375cd9c565dc@i12g2000prf.googlegroups.com>

I've got 2 perl scripts, both are code for ads. One script is admob,
the other is google. The code provided has been cut and pasted without
any mods. The admob code works, the google code doesn't and i get the
error,
syntax error at googleperlcode.cgi line 9, near "sub
google_append_color "
Can't use global @_ in "my" at googleperlcode.cgi line 10, near ", $_"
syntax error at googleperlcode.cgi line 12, near "}"
Execution of googleperlcode.cgi aborted due to compilation errors.

This is the actual google code,
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
ul class="simpleblue"
sub google_append_color {
  my @color_array = split(/,/, $_[0]);
  return $color_array[$_[1] % @color_array];
}

Anyone know why the errors ? Both files end in .cgi and both have the
permissions set the same, i.e 755. Both are in the same directory on
the server.


------------------------------

Date: Fri, 22 Feb 2008 10:55:33 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: BEGIN not safe after errors--compilation aborted
Message-Id: <47befe85$0$501$815e3792@news.qwest.net>

daz9643 wrote:
> I've got 2 perl scripts, both are code for ads. One script is admob,
> the other is google. The code provided has been cut and pasted without
> any mods. The admob code works, the google code doesn't and i get the
> error,
> syntax error at googleperlcode.cgi line 9, near "sub
> google_append_color "
> Can't use global @_ in "my" at googleperlcode.cgi line 10, near ", $_"
> syntax error at googleperlcode.cgi line 12, near "}"
> Execution of googleperlcode.cgi aborted due to compilation errors.
> 
> This is the actual google code,
> #!/usr/bin/perl
> use CGI::Carp qw(fatalsToBrowser);
> ul class="simpleblue"
    ^^^^^^^^^^^^^^^^^^^^^^
Does that look at all like it's valid syntax?

> sub google_append_color {
>   my @color_array = split(/,/, $_[0]);
>   return $color_array[$_[1] % @color_array];
> }
> 
> Anyone know why the errors ? Both files end in .cgi and both have the
> permissions set the same, i.e 755. Both are in the same directory on
> the server.


------------------------------

Date: Fri, 22 Feb 2008 18:48:17 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Broken links in Activestate Perl distribution
Message-Id: <RNEvj.49871$C61.38075@edtnps89>

Jaap Berkhout wrote:
> I installed the ActiveState Perl distribution (version 5.8.8) in my Windows
> XP Pro machine.  It seems there are a lot of broken hyperlinks in their
> documentation after the installation.  I got fed up with it, so I wrote the
> following script.  It solves my problem, ymmv.
> 

use warnings;
use strict;

> use File::DosGlob 'glob';

use Fcntl ':seek';

> @files_to_do = glob ("*.html");

my @files_to_do = glob ("*.html");

> foreach $file_to_do (@files_to_do) {

foreach my $file_to_do (@files_to_do) {

>    $file_to_do =~ /^(.*)\.html$/;
>    $file_name = $1;

    my ( $file_name ) = $file_to_do =~ /^(.*)\.html$/;

Or:

    ( my $file_name = $file_to_do ) =~ s/\.html$//;

>    open INFILE, "$file_to_do";

    open INFILE, '<', $file_to_do or die "Cannot open '$file_to_do' $!";

>    %newnames = ();

    my %newnames;

>    %names = ();

    my %names;

>    %refs = ();

    my %refs;

>    while (<INFILE>) {
>       chomp;
>       while ($_) {
>          if (s/.*?a name="([^"]+)"//) {
>             $names{$1} = 1;
>          } else {
>             $_ = "";
>          }
>       }
>    }

    while (<INFILE>) {
       while (/a name="([^"]+)"/g) {
          $names{$1} = 1;
       }
    }

> #   close INFILE;
> #   open INFILE, "$file_to_do";
>    seek (INFILE, 0, 0);

    seek INFILE, 0, SEEK_SET or die "Cannot seek on '$file_to_do' $!";

>    while (<INFILE>) {
>       chomp;
>       while ($_) {
>          if (s/.*?href="#([^"]+)"//) {
>             $refs{$1} = 1;
>          } else {
>             $_ = "";
>          }
>       }
>    }

    while (<INFILE>) {
       while (/href="#([^"]+)"/g) {
          $refs{$1} = 1;
       }
    }

> #   close INFILE;
>    foreach $name (keys (%names)) {

    foreach my $name (keys (%names)) {

>       next if $refs{$name};
>       $newname = "item_" . $name;
>       if ($refs{$newname}) {
>          $newnames{$name} = $newname;
>       }
>    }
> #   open INFILE, "$file_to_do";
>    open OUTFILE, ">${file_to_do}_new";

    open OUTFILE, '>', "${file_to_do}_new" or die "Cannot open 
'${file_to_do}_new' $!";

>    seek (INFILE, 0, 0);

    seek INFILE, 0, SEEK_SET or die "Cannot seek on '$file_to_do' $!";

>    while (<INFILE>) {
>       if (/(.*?a name="([^"]+)")(.*)/) {
>          $first = $1;
>          $second = $3;
>          if ($newnames{$2}) {
>             $newname = $newnames{$2};
>             $first =~ s/name="$2"/name="$newname"/;
>          }
>          print OUTFILE $first;
>          $_ = $second . "\n";
>          redo;
>       } else {
>          print OUTFILE $_;
>       }
>    }
>    close INFILE;
>    close OUTFILE;
>    if (!-e $file_to_do."_orig") {
>       rename ($file_to_do, $file_to_do."_orig");

       rename $file_to_do, $file_to_do."_orig" or die "Cannot rename 
'$file_to_do' to '${file_to_do}_orig' $!";

>       rename ($file_to_do."_new", $file_to_do);

       rename "${file_to_do}_new", $file_to_do or die "Cannot rename 
'$file_to_do' to '${file_to_do}_orig' $!";

>    }
> }


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Fri, 22 Feb 2008 12:46:31 -0800 (PST)
From: jhellma1@gmail.com
Subject: glob a directory then sort by timestamp
Message-Id: <0c8958e6-172d-433e-a6d6-76713d626096@h25g2000hsf.googlegroups.com>

All,

I am trying to glob a directory, storing the filenames into an array.
The trick is that I then want to sort that array by the files'
timestamps.  Is there an easy way to do this?

TIA!


------------------------------

Date: Fri, 22 Feb 2008 20:57:07 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: glob a directory then sort by timestamp
Message-Id: <rjdur39k8gnnj548srqhmckqs7l8u6o25r@4ax.com>

jhellma1@gmail.com wrote:
>I am trying to glob a directory, storing the filenames into an array.
>The trick is that I then want to sort that array by the files'
>timestamps.  Is there an easy way to do this?

Looping through and stat()ing hundreds or thousands of files individually is
going to be slow. Depending upon _which_ timestamp (created, accessed,
modified, ...) you want to sort by it may be significantly faster to call an
external program (e.g. ls) with the proper parameters and simply capture the
output.

jue


------------------------------

Date: Fri, 22 Feb 2008 10:39:43 -0800 (PST)
From: Jon Connell <ciamabue@googlemail.com>
Subject: Intention to take over Finance::Bank::Cahoot
Message-Id: <109b756c-7915-4819-a527-770b0f4b7218@n58g2000hsf.googlegroups.com>

Finance::Bank::Cahoot - currently owned by Andy Kelk (user ID mopoke)
- seems to have gone rather stale and the module that lived there
previously has been removed. The following module:

  http://search.cpan.org/~masaccio/Finance-Bank-Cahoot

is living in its place, but ownership of the namespace would need to
be transferred to me for it to be authorized.

Please let me know if you actually think you own this namespace (Andy
is not answering on his CPAN email address and it's started bouncing
email).

Jon.



------------------------------

Date: Fri, 22 Feb 2008 12:09:09 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Long line in perl script
Message-Id: <d36de0b0-c6ae-49af-a7b4-21f4ac63d4f5@e60g2000hsh.googlegroups.com>

On Feb 22, 2:43 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> rthangam wrote:
> > On Feb 22, 2:18 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> Looks weird to me. How about:
>
> >>                         if (
> >>                           $settings->{$service_name}->{'pin_home_dir'}
> >>                                                ||
> >>                           $settings->{$service_type}->{'pin_home_dir'}
> >>                         ) {
>
> > Did you using perl beautify ?
>
> What's that? Anyway, I didn't use any such thing.
>

s/perl beautify/perltidy/ perhaps ... ?

eg, perltidy output:

if (   $settings->{$service_name}->{'pin_home_dir'}
    || $settings->{$service_type}->{'pin_home_dir'} )
{

--
Charles DeRykus



------------------------------

Date: Fri, 22 Feb 2008 12:02:48 -0800
From: dummy@phony.info
Subject: Re: MAKE MONEY FAST USING EGOLD!!
Message-Id: <s8aur3pi0r374pmd6pc3nrn7bsmeq8ee85@4ax.com>

On Fri, 22 Feb 2008 04:39:46 -0800 (PST), elfrida8 <emachele@gmail.com>
wrote:

>You Can Laugh at Money Worries - if You Follow This Simple Plan! This
>is an opportunity for people who would like to work at home and have
>computer experience and are willing to invest time to get the
>lifestyle
>you have been wanting!
>
>READ ON: Read this entire message carefully! (Print it out or
>download
>it.)
>I found this on a bulletin board and decided to try it. A little
>while
>back, I was browsing through news groups and came across an article
>similar to this that said you could make thousands of
>dollars within weeks with only an initial investment of $6.00! So I
>thought, Yeah right, this must be a scam, but like most of us, I was
>curious, so I kept reading. Anyway, it said that you send only $1.00
>to
>each of the 6 Egold accounts stated in this article. You then place
>your name and address at the bottom of the list at the #6rd position
>and email it to your friends as well as post this message (with your
>email address in the list) to at least 200 newsgroups. (There are
>thousands) No catch, that was it. So after thinking it over, and
>talking to a few people first, I thought about trying it. I figured,
>what have I got to lose except $6.00, right? So I invested the measly
>$6.00.
>
>Well GUESS WHAT!! Within days, I started getting money coming into my
>Egold account! I was shocked! I figured it would end soon, but the
>money just kept coming in.
>
>In my first week, I made about $25.00, which means that 12 people
>joined the group after they saw my posted messages. By the end of
>the second week I had made a total of over $1000.00! In the third
>week I had over $10,000.00 and it's still growing.
>
>This is now my fourth week and I have made a total of just over
>$42,000.00 and itšs still coming in rapidly. It's certainly worth
>$6.00, and the few minutes it took to join Egold. I have spent more
>than that on the lottery!
>
>Let me tell you how this works and most importantly, why it works.
>Also, make sure you print a copy of this article NOW, so you can get
>the information off of it, as you need it. I promise you that if you
>follow the directions EXACTLY, that you will start making more money
>than you thought possible by doing something so easy!
>
>SUGGESTION: Read this entire message carefully! (Print it out or
>download it.) Follow the simple directions and watch the money comes
>in! It's that
>easy. It's legal. And, your investment is only $6.00.
>
>IMPORTANT: This is not a rip-off; it is not indecent; it is not
>illegal; and it is virtually no risk-it really works! If all of the
>following instructions are adhered to, you will receive extraordinary
>dividends.
>
>AGAIN, PLEASE NOTE: Follow these directions EXACTLY, and $20,000 or
>more can be yours in 4 to 6 weeks. This program remains successful
>because of the honesty and integrity of the participants. Please
>continue its success by carefully adhering to the instructions. In
>this
>business your product is not solid and tangible, it's a service. You
>are in the business of developing Mailing Lists.
>
>Many large corporations are happy to pay big bucks for quality lists.
>However, the money made from the mailing lists is secondary to the
>income, which is made from people like you and me asking to be
>included
>in that list.
>Here are the 4 easy steps to success:
>
>STEP 1:
>Take a few minutes to join Egold: here is the link:
>https://www.e-gold.com/newacct/newaccount.asp?cid=3D2682701 This is
>one
>of the best payment system in the Internet where your money is backed
>up by gold.
>
>STEP 2:
>Once you have your egold account running; use egold to post $1 to
>EACH
>of the 6 egold accounts below. Find the ways to upload money to your
>egold account with a credit card or other systems described on the
>egold site. It's easy and absolutely legal! You are requesting a
>legitimate service and you are paying for it! Like most of us I was a
>little skeptical and a little worried about the legal aspects of it
>all. But I looked around and did some homework and found it was
>perfectly legal. Here are the 6 individual egold accounts numbers
>that
>you have to send $1
>to for this to work properly and for you to receive money. (If you
>don't send the money and decide to post the message with your name in
>it anyway, you won't earn that much money you could have. If you did
>this you could get into serious trouble because it is fraud. So
>follow
>the instructions and post the $6 and you will make lots of money with
>no hassles.) Now send $1 to each of these following egold accounts
>from
>yours: and pay $1 to each the following 6 egold accounts. In the MEMO
>box type in Please add me to your mailing list - NOTE: if an egold
>account on the list is closed, just skip it and go on to the next
>account in the list.
>
>Here is the latest set of emails:
>
>
>1. 2087908
>2. 3197003
>3. 3200831
>4. 2632950
>5. 2682701
>6. 4992720
>
>STEP 3:
>After you sent money to these accounts take the #1 account off the
>list
>that you see above, move
>the other accounts up (6 becomes 5, 5 becomes 4) and add Your account
>as number 6 on the list.
>
>STEP 4:
>Change anything you need to, but try to keep this article as close to
>the original as possible. Now, post your amended article to at least
>200 newsgroups (there are thousands of groups). And email your
>message
>to as many people you can But remember, the more you post and email
>the
>more money you make! This is perfectly legal!
>
>If you have any doubts, refer to Title 18 Sec. 1302; 1241 of the
>Postal
>Lottery laws. Keep a copy of these steps for yourself and, whenever
>you
>need money, you can use it again and again.
>PLEASE REMEMBER: This program remains successful because of the
>honesty
>and integrity of the participants and by their carefully adhering to
>the directions. You are simply paying into a money making chain of
>participants and if the chain is broken you are taking away from the
>money making opportunities of someone else. So, as each person who
>joins the family and the directions are followed, three members will
>be
>reimbursed for their participation as a List Developer with one
>dollar
>each. You then insert your account into the list and it will move up
>geometrically. So that when your name reaches the #1 position you
>will
>have potentially received thousands of dollars into your account!!!
>
>What an opportunity for only a total of $6.00!! $1 for each of the
>first three people listed above. To begin with, please send you're
>joining fee now and then add your own account to the list and
>you're in business!
>
>HOW TO POST TO NEWS GROUPS?
>Use Netscape or Internet Explorer and try searching for various
>newsgroups (on-line forums, message boards, chat sites, discussions.)
>Log on any search engine like yahoo.com, google.com, altavista.com,
>excite.com, etc., then search with the subject "millionaire message
>board; or; money making message board; or; employment message board;
>or
>making discussions; or ''money making forum; or; business message
>board; etc. You will find thousands & thousands of message boards.
>Click on them one by one and you will find the option 'post a new
>message'. Then Post this article as a 'new message' by highlighting
>the
>text of this letter and selecting copy then paste from the edit menu.
>Fill in the Subject, this will be the header that everyone sees as
>they scroll through the list of postings in a particular group, click
>the post message button. You're done with your first one! It only
>takes
>about 60 seconds to complete postings on message boards after you
>catch
>on. REMEMBER, THE MORE NEWSGROUPS YOU POST IN, THE MORE MONEY YOU
>WILL
>MAKE!! BUT YOU HAVE TO POST A MINIMUM OF 200! That is it you will
>begin
>receiving money in your account from around the world within days!
>JUST
>MAKE SURE ALL THE ACCOUNTS ARE CORRECT.
>
>Now the WHY part out of 200 postings: Say I receive only 5 replies (a
>very low example). So then I made $5.00 with my number at #6 on the
>letter. Each of the 5 persons who just sent me $1.00 make the MINIMUM
>200 postings, each with my name at # 5 and only 5 persons respond to
>each of the original 5, this is an additional $25.00 for me. Now
>those
>24 each make 200 minimum posts with my name at #4 and only 5 replies
>each. This brings in an additional $125.00. Those 125 persons turn
>around and post the MINIMUM 200 with my account number at #3 and
>receive 5 replies each, I will make an additional $625.00. Ok, now
>here
>is the FUN part, each of those 625 people post a MINIMUM of 200
>letters
>with my number at #2 and they receive 5 replies each. That just made
>me
>$3,125.00!!! Those 3125 persons will all deliver this message to 200
>newsgroups with my number at #1 and if still 5 persons per 200 react,
>I
>will receive an additional $15,625.00!! With an investment of only
>$6.00!!
>A - M - A - Z - I - N - G -!!
>When your number is no longer on the list, you just take the latest
>posting in the newsgroups, and send out another $6.00 to egold
>numbers
>on the list, putting your account at number 6 again. And start
>posting
>again. The thing to remember is that thousands of people all over the
>world are joining the Internet and reading these articles everyday.
>JUST LIKE YOU ARE NOW!! So, can you afford $6.00 to see if it really
>works!! People have said what if the plan is played out and no one
>sends you the money? So what! What are the chances of that happening
>when there are tons of new honest users and new honest people who are
>joining the Internet & newsgroups everyday and are willing to give it
>a
>try??
>
>

This old scam seems to still be around. For very young and gullible
readers it may be necessary to point out that this is an illegal (in all
countries I know of) chain letter that will benefit only the crook that
started it. 


------------------------------

Date: Fri, 22 Feb 2008 06:13:21 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: setting %ENV in a module
Message-Id: <b4ae604d-7dca-484c-bfbe-bb6ab2fd0b70@e23g2000prf.googlegroups.com>

On Feb 21, 12:50 pm, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <0d055ad0-b659-4ae8-b907-01e482fce...@i12g2000prf.googlegroups.com>,
>
> pgodfrin <pgodf...@gmail.com> wrote:
> > Well - here's the scoop. I believe this is not necessarily a scoping
> > issue, but one of understanding how perl interprets environment
> > variables. (or maybe how I interpret how... <grin>). It appears that
> > if one tries to set $ENV{VARNAME}="$ENV-VAR" (with or without quotes)
> > then the resulting hash value is the literal $ENV-VAR - perl is not
> > evaluating the scalar variable. (as opposed to use Env qw(VAR-NAME)
> > which permits using $VAR-NAME as a scalar variable in the subsequent
> > code).
>
> That is most definitely not true. You are extracting the string
> '$TMPTEST' from a string using a regular expression and storing it into
> the variable $v. When you assign the value of $v, using the expression
> "$v", to the value of the %ENV hash, that string gets stored as is. If
> you want to evaluate what $v contains as a Perl expression, then you
> should use the eval operator:
>
>   $ENV{$e} = eval $v;
>
> See the difference here:
>
> % perl -e '$x=q($y);$y="abc";print $x,"\n";'
> $y
> % perl -e '$x=q($y);$y="abc";print eval $x,"\n";'
> abc
>
> The Env package (I have not used it) ties the values of the members of
> %ENV to scalar variables (and arrays if needed), so it will tie
> $ENV{TMPTEST} to $TMPTEST, and changing one will change the other.
> Perhaps this fact is confusing you. If so, you might be better off not
> using Env.pm and sticking to just using %ENV.
>
>
>
>
>
> > I'm a little stumped as to why.
>
> > the input file (I'd like to be compatible with unix export statements.
> > I strip that out later)
> >   export TMPTEST=/tmp
> >   export TMPTOO=$TMPTEST
>
> > The simplified module:
> >   package MymodSimp;
> >   use Env;
> >   Env::import;
> >   my(@rvars,$l,$e,$v);
> >   open RVARS,"/home/pgodfrin/perl/et/etfile" ;
> >   @rvars=<RVARS>; close RVARS;
> >   foreach (@rvars)
> >   {
> >         if (!/(^export)(\s+)\w+=/) { next;}  # skips garbage
> >         ($l,$e,$v) = (/^(export\s+)(\w+)=(.+)/);
> >         $ENV{$e}="$v";
> >   }
> >   $ENV{TMPTREE}='myliteral';
> > 1;
>
> It is an inefficient use of memory to read a file into an array,
> process the lines of that array one-at-a-time, and discard the array.
> It is more efficient to process the lines when they are read.
>
> There is no need to use two identical regular expressions to test for a
> match and then extract data. Do it in one step.
>
> It is better to use private variables for file handles and use the
> three-argument version of open.
>
> There is no need to quote scalar variables.
>
> Therefore:
>
> package MymodSimp;
> open my $rvars, '<', "/home/pgodfrin/perl/et/etfile" ;
> foreach (<$rvars>)
> {
>   if( /^export\s+(\w+)=(.+)/ ) {
>     $ENV{$1}=$2;
>   }}
>
> $ENV{TMPTREE}='myliteral';
> 1;
>
>
>
> > The calling program:
> > [pgodfrin:~/perl/et]> cat envtest
> > #!/usr/bin/perl
>
> use strict;
>
>
>
> > use warnings;
> > no warnings 'once';
> > use Env;
> > Env::import;
> > use MymodSimp ;
>
> > $ENV{TMPFOUR}="$TMPTOO";
> > $ENV{TMPFIVE}=$ENV{TMPTEST};
> > print "TMPTEST:  $ENV{TMPTEST}\n";
> > print "TMPTOO:   $ENV{TMPTOO}\n";
> > print "TMPTREE:  $ENV{TMPTREE}\n";
> > print "TMPFOUR:  $ENV{TMPFOUR}\n";
> > print "TMPFIVE:  $ENV{TMPFIVE}\n";
>
> > chdir("$TMPTEST") or die "Can't change dir to $TMPTEST\n";
> > print "Change to dir $TMPTEST:"; system("pwd"); print "\n";
> > chdir("$TMPTOO") or die "Can't change dir to $TMPTOO\n";
> > print "Change to dir $TMPTOO:"; system("pwd"); print "\n";
> > chdir("$TMPFIVE") or die "Can't change dir to $TMPFIVE\n";
> > print "Change to dir $TMPFIVE:"; system("pwd"); print "\n";
>
> > exit;
>
> > The execution.
> > [pgodfrin:~/perl/et]> envtest
> > TMPTEST:  /tmp
> > TMPTOO:   $TMPTEST
> > TMPTREE:  myliteral
> > TMPFOUR:  $TMPTEST
> > TMPFIVE:  /tmp
> > Change to dir /tmp:/tmp
>
> > Can't change dir to $TMPTEST
>
> > So - setting $ENV{TMPTOO}="$TMPTEST" doesn't evaluate the variable.
>
> It does, but that is not what you are doing. You are doing
>
>   $ENV{TMPTOO} = "$TMPTOO";
>
> where $TMPTOO contains '$TMPTEST'.
>
> --
> Jim Gibson
>
>  Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
>     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
>                http://www.usenet.com

Hi - I knew there was a better way! I will try this out. I realized as
I was posting my code that it is indeed silly to dump the file into
memory. I've changed that. Why is the three argument version of open
better though?

thanks,
pg


------------------------------

Date: Fri, 22 Feb 2008 10:56:20 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: setting %ENV in a module
Message-Id: <220220081056207785%jimsgibson@gmail.com>

In article
<b4ae604d-7dca-484c-bfbe-bb6ab2fd0b70@e23g2000prf.googlegroups.com>,
pgodfrin <pgodfrin@gmail.com> wrote:


> Hi - I knew there was a better way! I will try this out. I realized as
> I was posting my code that it is indeed silly to dump the file into
> memory. I've changed that. Why is the three argument version of open
> better though?

It is more explicit and more flexible. See 'perldoc -f open' for all
the things you can do with the 3-argument version of open. For simple
programs, it doesn't really matter. But for more complicated programs,
the explicitness is helpful and consistency is good for
maintainability.

One slightly facetious difference: with 2-argument open you can't open
a file named '<stupid_file_name.txt'.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Fri, 22 Feb 2008 20:21:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: setting %ENV in a module
Message-Id: <ifn395-002.ln1@osiris.mauzo.dyndns.org>


Quoth Jim Gibson <jimsgibson@gmail.com>:
> In article
> <b4ae604d-7dca-484c-bfbe-bb6ab2fd0b70@e23g2000prf.googlegroups.com>,
> pgodfrin <pgodfrin@gmail.com> wrote:
> 
> > Hi - I knew there was a better way! I will try this out. I realized as
> > I was posting my code that it is indeed silly to dump the file into
> > memory. I've changed that. Why is the three argument version of open
> > better though?
> 
> It is more explicit and more flexible. See 'perldoc -f open' for all
> the things you can do with the 3-argument version of open. For simple
> programs, it doesn't really matter. But for more complicated programs,
> the explicitness is helpful and consistency is good for
> maintainability.
> 
> One slightly facetious difference: with 2-argument open you can't open
> a file named '<stupid_file_name.txt'.

Much more importantly, if someone passes you a filename of 
'rm -rf /; echo |' you won't delete all your files by mistake.

Ben



------------------------------

Date: Fri, 22 Feb 2008 10:38:12 -0800 (PST)
From: Petyr David <phynkel@gmail.com>
Subject: Speeding my script
Message-Id: <29fba8f0-26f0-4b2e-9dbd-637445719e09@n77g2000hse.googlegroups.com>

have a web page calling PERL script that searches for patterns in 20,
000 files + and returns link to files and lines found matching
pattern. I use a call to `find` and `egrep`

Q: Script works - but is straining under the load - files are in the
Gbs.
     How to speed process? How simple to employ threads or slitting
off
     new processes?

    I know i should RTFM (LOL) and I will, but just looking for some
quick guidance/suggestions

 pseudo code;

 cd root of document directory

 Load array with names of directories

 forech subdir in @dirnames

      cd $subdir
      lots of if statements to figure what find command and what
option to use
      @temp_array=`$long_find_grep_command`
       push @temp_array onto big array
       other processing
end foreach

what I'd like to do is to be able to simultaneously be searching more
than 1 subdirectory

TX for your help -




------------------------------

Date: Fri, 22 Feb 2008 10:48:22 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Speeding my script
Message-Id: <e64f16cb-6069-4e89-85ee-0b3ba3dbe923@h11g2000prf.googlegroups.com>

On Feb 22, 1:38 pm, Petyr David <phyn...@gmail.com> wrote:
> have a web page calling PERL script that searches for patterns in 20,
> 000 files + and returns link to files and lines found matching
> pattern. I use a call to `find` and `egrep`
>
> Q: Script works - but is straining under the load - files are in the
> Gbs.
>      How to speed process? How simple to employ threads or slitting
> off
>      new processes?
>
>     I know i should RTFM (LOL) and I will, but just looking for some
> quick guidance/suggestions
>
>  pseudo code;
>
>  cd root of document directory
>
>  Load array with names of directories
>
>  forech subdir in @dirnames
>
>       cd $subdir
>       lots of if statements to figure what find command and what
> option to use
>       @temp_array=`$long_find_grep_command`
>        push @temp_array onto big array
>        other processing
> end foreach
>
> what I'd like to do is to be able to simultaneously be searching more
> than 1 subdirectory
>
> TX for your help -

Your idea is only likely to help if the directories reside on
different
disks, otherwise it will slow down the search by thrashing the disks.

Better would be to analyze the type of requests.  Maybe there
are common searches you can cache. For example, a search for
/the magic words are squeamish ossifrage/ need only be performed
on files known to contain the common word "ossifrage".


------------------------------

Date: Fri, 22 Feb 2008 11:23:47 -0800 (PST)
From: "cvh@LE" <christian.hansel@cpi-service.com>
Subject: Re: Speeding my script
Message-Id: <6b2ed337-c94a-417f-bdb5-0013d354ca00@e23g2000prf.googlegroups.com>

On Feb 22, 7:48 pm, smallpond <smallp...@juno.com> wrote:
> On Feb 22, 1:38 pm, Petyr David <phyn...@gmail.com> wrote:
>
>
>
> > have a web page calling PERL script that searches for patterns in 20,
> > 000 files + and returns link to files and lines found matching
> > pattern. I use a call to `find` and `egrep`
>
> > Q: Script works - but is straining under the load - files are in the
> > Gbs.
> >      How to speed process? How simple to employ threads or slitting
> > off
> >      new processes?
>
> >     I know i should RTFM (LOL) and I will, but just looking for some
> > quick guidance/suggestions
>
> >  pseudo code;
>
> >  cd root of document directory
>
> >  Load array with names of directories
>
> >  forech subdir in @dirnames
>
> >       cd $subdir
> >       lots of if statements to figure what find command and what
> > option to use
> >       @temp_array=`$long_find_grep_command`
> >        push @temp_array onto big array
> >        other processing
> > end foreach
>
> > what I'd like to do is to be able to simultaneously be searching more
> > than 1 subdirectory
>
> > TX for your help -
>
> Your idea is only likely to help if the directories reside on
> different
> disks, otherwise it will slow down the search by thrashing the disks.
>
> Better would be to analyze the type of requests.  Maybe there
> are common searches you can cache. For example, a search for
> /the magic words are squeamish ossifrage/ need only be performed
> on files known to contain the common word "ossifrage".

To me this very much sounds like the 20k+ files are changed too often.
If this is the case you very likely might be able to speed up the
process by using an index of some sort which is updated by another
perl-process in regular periods, i.e. running as cron. I personally
recommend a sql database of some sort against which your web-request
run their queries.
this db can be updated every x mins.

another idea could be to have various flat-file index-database against
which you query using awk in subprocesses, since awk can be a lot
faster than perl in specific cases ...



------------------------------

Date: Fri, 22 Feb 2008 13:48:52 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Speeding my script
Message-Id: <47bf2725$0$3573$815e3792@news.qwest.net>

Petyr David wrote:
> have a web page calling PERL script that searches for patterns in 20,
> 000 files + and returns link to files and lines found matching
> pattern. I use a call to `find` and `egrep`
> 
> Q: Script works - but is straining under the load - files are in the
> Gbs.
>      How to speed process? How simple to employ threads or slitting
> off
>      new processes?
> 
>     I know i should RTFM (LOL) and I will, but just looking for some
> quick guidance/suggestions

No need to LOL at your laziness.

Using find/grep on thousands of files and Gb of data is a poor
choice.  Try looking at various indexing tools: htdig, glimpse,
Swish-e, etc.


------------------------------

Date: Fri, 22 Feb 2008 11:01:21 -0800 (PST)
From: John <chunji08@gmail.com>
Subject: Split a string in perl
Message-Id: <0d8f2389-94c4-4dab-bbb9-e5eab6cec139@u69g2000hse.googlegroups.com>



There must be something that I have ignored in PERL.

To split a string with delimiter "|", sometimes, I need to give "\",
sometimes it works for "\\" only.

Here are the details.

The String is " 0000|Null".

And the ways I have tried to do split are:
1. my @columns  = split('\|', $String);
2. my ( $proj, $desc) = split('\|', $String);
3. my ( $proj, $desc) = split('\\|', $String);

Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
receive an empty string .

What was wrong with case 2 , I thought if Case 1 works, Case2 should
be working also, Right ?  I am using perl 5.6.1 on linux box.



Thanks a lot for the tips.


John.







------------------------------

Date: Fri, 22 Feb 2008 11:56:01 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Split a string in perl
Message-Id: <9a584bdb-9a52-4f1a-8bfa-ba084eb74f31@i7g2000prf.googlegroups.com>

On Feb 22, 11:01 am, John <chunj...@gmail.com> wrote:
> There must be something that I have ignored in PERL.
>
> To split a string with delimiter "|", sometimes, I need to give "\",
> sometimes it works for "\\" only.
>
> Here are the details.
>
> The String is " 0000|Null".
>
> And the ways I have tried to do split are:
> 1. my @columns  = split('\|', $String);
> 2. my ( $proj, $desc) = split('\|', $String);
> 3. my ( $proj, $desc) = split('\\|', $String);
>
> Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
> receive an empty string .
>
> What was wrong with case 2 , I thought if Case 1 works, Case2 should
> be working also, Right ?  I am using perl 5.6.1 on linux box.
>

case 2 works as is.  Is it possible you meant:
split( "\|", $String ) ...?

In that case, double-quotish interpolation causes
your split regex to be just '|':

# perl -MO=Deparse,-p -e 'split "\|"," 0000|Null"'
split(/|/, ' 0000|Null', 0);
-e syntax OK

Then, you have the alternation meta character
alone with empty alternatives on either side
which'll match the 1st 2 characters encountered:

  $proj=' '  $desc='0'

Is it possible you had 2 leading blanks in
string which "looked" like 2 empty strings for
$proj and $desc...

--
Charles DeRykus


------------------------------

Date: Fri, 22 Feb 2008 12:17:43 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Split a string in perl
Message-Id: <220220081217430727%jimsgibson@gmail.com>

In article
<0d8f2389-94c4-4dab-bbb9-e5eab6cec139@u69g2000hse.googlegroups.com>,
John <chunji08@gmail.com> wrote:

> There must be something that I have ignored in PERL.
> 
> To split a string with delimiter "|", sometimes, I need to give "\",
> sometimes it works for "\\" only.
> 
> Here are the details.
> 
> The String is " 0000|Null".
> 
> And the ways I have tried to do split are:
> 1. my @columns  = split('\|', $String);
> 2. my ( $proj, $desc) = split('\|', $String);
> 3. my ( $proj, $desc) = split('\\|', $String);
> 
> Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
> receive an empty string .
> 
> What was wrong with case 2 , I thought if Case 1 works, Case2 should
> be working also, Right ?  I am using perl 5.6.1 on linux box.

It helps if you post a complete, short program that demonstrates your
problem and that anyone can run, like this:

#!/usr/local/bin/perl
use strict;
use warnings;

my $String = " 0000|Null";

my @columns  = split('\|', $String);
print join(',',@columns),"\n";

my ( $proj, $desc) = split('\|', $String);
print "proj=$proj, desc=$desc\n";

( $proj, $desc) = split('\\|', $String);
print "proj=$proj, desc=$desc\n";


Output:

 0000,Null
proj= 0000, desc=Null
proj= 0000, desc=Null


So they all work on my system (Perl 5.8.8).

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Fri, 22 Feb 2008 12:29:10 -0800
From: dummy@phony.info
Subject: Re: Split a string in perl
Message-Id: <4qbur3tmdr3qjirr590mtvp0ge36v4v9vp@4ax.com>

On Fri, 22 Feb 2008 11:01:21 -0800 (PST), John <chunji08@gmail.com>
wrote:

>
>
>There must be something that I have ignored in PERL.
>
>To split a string with delimiter "|", sometimes, I need to give "\",
>sometimes it works for "\\" only.
>
>Here are the details.
>
>The String is " 0000|Null".
>
>And the ways I have tried to do split are:
>1. my @columns  = split('\|', $String);
>2. my ( $proj, $desc) = split('\|', $String);
>3. my ( $proj, $desc) = split('\\|', $String);
>
>Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
>receive an empty string .
>
>What was wrong with case 2 , I thought if Case 1 works, Case2 should
>be working also, Right ?  I am using perl 5.6.1 on linux box.
>
>
>
>Thanks a lot for the tips.
>
>
>John.
>
>
>
>

The first param for split() is a regex, so __ split /\|/, $String __ is
correct in all cases you gave.


------------------------------

Date: Fri, 22 Feb 2008 20:24:51 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Split a string in perl
Message-Id: <jln395-002.ln1@osiris.mauzo.dyndns.org>


Quoth John <chunji08@gmail.com>:
> 
> There must be something that I have ignored in PERL.
> 
> To split a string with delimiter "|", sometimes, I need to give "\",
> sometimes it works for "\\" only.
> 
> Here are the details.
> 
> The String is " 0000|Null".
> 
> And the ways I have tried to do split are:
> 1. my @columns  = split('\|', $String);
> 2. my ( $proj, $desc) = split('\|', $String);

The first argument to split is a regex (with the special exception of 
' '). Don't pass something that looks like a string, you'll just confuse
yourself.

    my (@proj, $desc) = split(/\|/, $String);

Ben



------------------------------

Date: Fri, 22 Feb 2008 12:34:46 -0800 (PST)
From: John <chunji08@gmail.com>
Subject: Re: Split a string in perl
Message-Id: <618aff70-67d0-4b08-a249-df35988f7a73@e10g2000prf.googlegroups.com>

On Feb 22, 11:56=A0am, "comp.llang.perl.moderated" <c...@blv-
sam-01.ca.boeing.com> wrote:
> On Feb 22, 11:01 am, John <chunj...@gmail.com> wrote:
>
>
>
>
>
> > There must be something that I have ignored in PERL.
>
> > To split a string with delimiter "|", sometimes, I need to give "\",
> > sometimes it works for "\\" only.
>
> > Here are the details.
>
> > The String is " 0000|Null".
>
> > And the ways I have tried to do split are:
> > 1. my @columns =A0=3D split('\|', $String);
> > 2. my ( $proj, $desc) =3D split('\|', $String);
> > 3. my ( $proj, $desc) =3D split('\\|', $String);
>
> > Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
> > receive an empty string .
>
> > What was wrong with case 2 , I thought if Case 1 works, Case2 should
> > be working also, Right ? =A0I am using perl 5.6.1 on linux box.
>
> case 2 works as is. =A0Is it possible you meant:
> split( "\|", $String ) ...?
>
> In that case, double-quotish interpolation causes
> your split regex to be just '|':
>
> # perl -MO=3DDeparse,-p -e 'split "\|"," 0000|Null"'
> split(/|/, ' 0000|Null', 0);
> -e syntax OK
>
> Then, you have the alternation meta character
> alone with empty alternatives on either side
> which'll match the 1st 2 characters encountered:
>
> =A0 $proj=3D' ' =A0$desc=3D'0'
>
> Is it possible you had 2 leading blanks in
> string which "looked" like 2 empty strings for
> $proj and $desc...
>
> --
> Charles DeRykus- Hide quoted text -
>
> - Show quoted text -

I do not have any leading blanks in this String.

-John


------------------------------

Date: Fri, 22 Feb 2008 20:37:27 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Split a string in perl
Message-Id: <3gcur31k76gbqi6oqc465d2d2g58b1mg6h@4ax.com>

John <chunji08@gmail.com> wrote:
>
>
>There must be something that I have ignored in PERL.
>
>To split a string with delimiter "|", sometimes, I need to give "\",
>sometimes it works for "\\" only.
>
>Here are the details.
>
>The String is " 0000|Null".
>
>And the ways I have tried to do split are:
>1. my @columns  = split('\|', $String);
>2. my ( $proj, $desc) = split('\|', $String);
>3. my ( $proj, $desc) = split('\\|', $String);
>
>Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
>receive an empty string .

I cannot reproduce your results:

C:\tmp>type t.pl
use strict; use warnings;
my $String = " 0000|Null";
my @columns  = split('\|', $String);
print "@columns\n";
my ( $proj, $desc) = split('\|', $String);
print $proj, ' ', $desc, "\n";
( $proj, $desc) = split('\\|', $String);
print $proj, ' ', $desc , "\n";

C:\tmp>t.pl
 0000 Null
 0000 Null
 0000 Null

Each of versions produces the same result as the others.

jue


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1299
***************************************


home help back first fref pref prev next nref lref last post