[25453] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7698 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 27 00:05:31 2005

Date: Wed, 26 Jan 2005 21:05:10 -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           Wed, 26 Jan 2005     Volume: 10 Number: 7698

Today's topics:
    Re: 20050126 find replace strings in file <tadmc@augustmail.com>
    Re: 20050126 find replace strings in file <cwilbur@mithril.chromatico.net>
    Re: [perl-python] 20050125 standard modules <gargoyle@no.spam>
    Re: [perl-python] 20050126 find replace strings in file <jurgenex@hotmail.com>
    Re: [perl-python] 20050126 find replace strings in file <emschwar@fc.hp.com>
        Arbitrary decimal places in addition (Matthew Keene)
    Re: Arbitrary decimal places in addition <matternc@comcast.net>
    Re: Arbitrary decimal places in addition <jurgenex@hotmail.com>
    Re: ASP Perlscript/VBScript Order of execution <janschiffman@hotmail.com>
    Re: ASP Perlscript/VBScript Order of execution <jurgenex@hotmail.com>
    Re: ASP Perlscript/VBScript Order of execution <janschiffman@hotmail.com>
    Re: FAQ 6.17 Why don't word-boundary searches with "\b" (Anno Siegel)
    Re: how do u convert a string to a date <toreau@gmail.com>
    Re: how do u convert a string to a date <someone@example.com>
    Re: Old tutorial - now corrected <tadmc@augustmail.com>
    Re: Perl error <jurgenex@hotmail.com>
        Regex for finding email addresses inside text file <doug@taperedsquare.com>
    Re: Regex for finding email addresses inside text file <tadmc@augustmail.com>
    Re: Regex for finding email addresses inside text file <jurgenex@hotmail.com>
        Regexp kicking my ass <google@ttsg.com>
    Re: Regexp kicking my ass <see_sig@invalid>
        Why does glob() work in while loop? (J. Romano)
    Re: Why does glob() work in while loop? <see_sig@invalid>
    Re: Why does glob() work in while loop? (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Jan 2005 20:13:36 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: 20050126 find replace strings in file
Message-Id: <slrncvgjig.2al.tadmc@magna.augustmail.com>


[ Followup set ]


Dan Perl <danperl@rogers.com> wrote:

> I can't imagine why or how, but there are 
> actually 26 members in the perl-python Yahoo! group who have registered to 
> get these bogus lessons sent to them daily!


There is one born every minute.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 27 Jan 2005 03:19:25 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: 20050126 find replace strings in file
Message-Id: <871xc7zhrh.fsf@mithril.chromatico.net>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

    TM> [ Followup set ]


    TM> Dan Perl <danperl@rogers.com> wrote:

    >> I can't imagine why or how, but there are actually 26 members
    >> in the perl-python Yahoo! group who have registered to get
    >> these bogus lessons sent to them daily!

    TM> There is one born every minute.

And when I poked at the list to see if I could figure out who was
subscribing, it appeared to me that at least one of the subscribers
was a comp.lang.lisp regular with such generosity of spirit or free
time and pain tolerance as to go to Xah's playground and correct his
errors *there*.

The other 25 - eh.  The optimist in me says I won't have to worry
about them when competing for jobs; the pessimist in me knows I'll be
hired to maintain their code but forbidden to improve it.

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


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

Date: Wed, 26 Jan 2005 23:25:22 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: [perl-python] 20050125 standard modules
Message-Id: <CFVJd.32657$8W4.4669@bignews6.bellsouth.net>

On 2005-01-25, Dan Perl <danperl@rogers.com> wrote:
> I wish there was a good way like that to stop these daily postings!

use killfile;
undef $xah_lee and read(NEWS, $peacefully, 0xd00d);


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

Date: Wed, 26 Jan 2005 23:51:06 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [perl-python] 20050126 find replace strings in file
Message-Id: <K1WJd.818$u45.727@trnddc08>

Xah Lee wrote:
[...]
> In perl, similar code can be achieved.
> the following code illustrates.
>
> if (scalar @ARGV != 4)

Why scalar()? The comparison already creates a scalar context, no need to 
enforce it twice.

>  {die "Wrong arg! Unix BNF: $0 <sstr> <rstr>
> <file id1> <file id2>\n"}
> $stext=$ARGV[0];
> $rtext=$ARGV[1];
> $infile = $ARGV[2];
> $outfile = $ARGV[3];

Ouch, how ugly. What's wrong with a simple
    my ($one, $two, $three, $four) = @ARGV;

or the standard way using shift
    for ($one, $two, $three, $four) {
        $_ = shift;
    }

> open(F1, "<$infile") or die "Perl fucked up. Reason: $!";
> open(F2, ">$outfile") or die "Perl fucked up. Reason: $!";

Really? Usually it's either the OS or the user (disk full, no write 
permissions, wrong file name, ...)

> while ($line = <F1>) {

Why $line? It doesn't serve any useful purpose here.

> chomp($line);

Why chomp()? It doesn't serve any useful purpose here.

> $line =~ s/$stext/$rtext/g;

If you would not have used $line above then you would not need the binding 
here.

> print F2 "$line\n";

If you would not have chomped the line above then you would not need to add 
the newline back here. A simpler
    print F2 $_;
would have sufficed

> }
> close(F1) or die "Perl fucked up. Reason: $!";
> close(F2) or die "Perl fucked up. Reason: $!";

I find this highly unlikely. If at all then the OS failed to complete the 
close.

jue 




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

Date: Wed, 26 Jan 2005 18:19:49 -0700
From: Eric Schwartz <emschwar@fc.hp.com>
Subject: Re: [perl-python] 20050126 find replace strings in file
Message-Id: <etomzuvsm6i.fsf@wilson.emschwar>

To follow up on Jurgen Exner's critique, I present Xah Lee's version, and
then my rewritten version.

"Xah Lee" <xah@xahlee.org> writes:
> if (scalar @ARGV != 4) {die "Wrong arg! Unix BNF: $0 <sstr> <rstr>
> <file id1> <file id2>\n"}
> $stext=$ARGV[0];
> $rtext=$ARGV[1];
> $infile = $ARGV[2];
> $outfile = $ARGV[3];
> open(F1, "<$infile") or die "Perl fucked up. Reason: $!";
> open(F2, ">$outfile") or die "Perl fucked up. Reason: $!";
> while ($line = <F1>) {
> chomp($line);
> $line =~ s/$stext/$rtext/g;
> print F2 "$line\n";
> }
> close(F1) or die "Perl fucked up. Reason: $!";
> close(F2) or die "Perl fucked up. Reason: $!";

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

if (@ARGV != 4) {
   die "Wrong arg! Unix BNF: $0 <sstr> <rstr> <file id1> <file id2>" 
}
my ($stext, $rtext, $infile, $outfile) = @ARGV;

open my $infh, '<', $infile
     or die "Error opening input file [$infile]: $!";
open my $outfh, '>', $outfile
     or die "Error opening output file [$outfile]: $!";

while(<$infh>) {
    s/$stext/$rtext/g;
    print { $outfh } $_;
}
close($infh) or die "Error closing input file [$infile]: $!";
close($outfh) or die "Error closing output file [$outfile]: $!";

My version takes up more lines, but I don't count whitespace--
whitespace is not expensive, and when used properly adds greatly to
the readability of your program.

I've set followups to the only appropriate group for Mr. Lee's
postings.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 26 Jan 2005 17:21:44 -0800
From: dfg778@yahoo.com.au (Matthew Keene)
Subject: Arbitrary decimal places in addition
Message-Id: <bb27253c.0501261721.214b3b52@posting.google.com>

I'm sure this question has been asked before, but I couldn't find
anything that really satisfactorily explained it, so please excuse me
if I'm going over old ground.

We have a program which totals decimal numbers in a file.  The code in
the program looks something like this (I've added the print statements
to see what's going on):

use English ;

open (FILE,"DMD_WKG_FCT.TXT") or die "Couldn't open file" ;
while (defined($line = <FILE>)) {
  chomp $line ;
  @fields = split(/\t/,$line) ;
  next if $INPUT_LINE_NUMBER == 1 ;
  print "Input field = $fields[11] $sum\n" ;
}

print $sum ;

and the output that this produces looks like this (I've trimmed the
output to show the sections which illustrate the behaviour I'm talking
about)

Input field = 2.5237 Running total = 9864.4567
Input field = 0.8571 Running total = 9865.3138
Input field = 0.8571 Running total = 9866.1709
Input field = 15.6639 Running total = 9881.8348
Input field = 16.6392 Running total = 9898.47399999999
Input field = 6.6188 Running total = 9905.09279999999
Input field = 19.9114 Running total = 9925.0042
Input field = 0.0000 Running total = 9925.0042
Input field = 0.0000 Running total = 9925.0042
Input field = 0.0000 Running total = 9925.0042
Input field = 0.0000 Running total = 9925.0042
Input field = 0.0001 Running total = 9925.0043
Input field = 0.0001 Running total = 9925.00439999999
Input field = 0.0001 Running total = 9925.00449999999
Input field = 0.0001 Running total = 9925.00459999999
Input field = 4.0370 Running total = 9929.04159999999

Where did the extra decimal places come from ?

Now, we could probably solve this by rounding all numbers to 4 decimal
places, but the problem is that this is a utility program which is
meant to be able to handle an arbitrary number of decimal places, so
we wouldn't necessary know how many decimal places to round to (I
guess we could find the greatest number of decimal places in the input
and round to that, but this seems to be getting a bit silly).

Can anybody explain this behaviour and the best way to get around it ?


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

Date: Wed, 26 Jan 2005 21:03:45 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Arbitrary decimal places in addition
Message-Id: <msOdnW6sEb-f0WXcRVn-qw@comcast.com>

Matthew Keene wrote:

> I'm sure this question has been asked before, but I couldn't find
> anything that really satisfactorily explained it, so please excuse me
> if I'm going over old ground.
> 
> We have a program which totals decimal numbers in a file.  The code in
> the program looks something like this (I've added the print statements
> to see what's going on):
> 
> use English ;
> 
> open (FILE,"DMD_WKG_FCT.TXT") or die "Couldn't open file" ;
> while (defined($line = <FILE>)) {
>   chomp $line ;
>   @fields = split(/\t/,$line) ;
>   next if $INPUT_LINE_NUMBER == 1 ;
>   print "Input field = $fields[11] $sum\n" ;
> }
> 
> print $sum ;
> 
> and the output that this produces looks like this (I've trimmed the
> output to show the sections which illustrate the behaviour I'm talking
> about)
> 
> Input field = 2.5237 Running total = 9864.4567
> Input field = 0.8571 Running total = 9865.3138
> Input field = 0.8571 Running total = 9866.1709
> Input field = 15.6639 Running total = 9881.8348
> Input field = 16.6392 Running total = 9898.47399999999
> Input field = 6.6188 Running total = 9905.09279999999
> Input field = 19.9114 Running total = 9925.0042
> Input field = 0.0000 Running total = 9925.0042
> Input field = 0.0000 Running total = 9925.0042
> Input field = 0.0000 Running total = 9925.0042
> Input field = 0.0000 Running total = 9925.0042
> Input field = 0.0001 Running total = 9925.0043
> Input field = 0.0001 Running total = 9925.00439999999
> Input field = 0.0001 Running total = 9925.00449999999
> Input field = 0.0001 Running total = 9925.00459999999
> Input field = 4.0370 Running total = 9929.04159999999
> 
> Where did the extra decimal places come from ?

Rounding errors.  The computer is not doing the arithmetic in decimal,
and so cannot always represent your decimal fractions with complete
accuracy.  It must often round when converting your input.  In particular,
0.0001 is a non-terminating decimal in binary floating point.
Sometimes the rounding errors show up in your output.  Among other things,
this results in the First Commandment of Floating Point: "Thou shalt
not compare two floats for equality," since you can't count on the
rounding errors having made them unequal when they shouldn't be.
> 
> Now, we could probably solve this by rounding all numbers to 4 decimal
> places, but the problem is that this is a utility program which is
> meant to be able to handle an arbitrary number of decimal places, so
> we wouldn't necessary know how many decimal places to round to (I
> guess we could find the greatest number of decimal places in the input
> and round to that, but this seems to be getting a bit silly).
> 
> Can anybody explain this behaviour and the best way to get around it ?

Basically, if you must have arbitrary precision, you're going to have to
go out and get it; look at the Math::BigFloat package that's standard.
Note that you *still* have to know what precision and accuracy you want.

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Thu, 27 Jan 2005 02:47:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Arbitrary decimal places in addition
Message-Id: <xDYJd.1329$SP4.409@trnddc07>

Matthew Keene wrote:
[...]
> Input field = 0.0001 Running total = 9925.00449999999
> Where did the extra decimal places come from ?
[...]

Your Question is Asked Frequently, please see "perldoc -q 9999" for the 
answer.

jue 




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

Date: 26 Jan 2005 17:02:43 -0800
From: "LinnAxis" <janschiffman@hotmail.com>
Subject: Re: ASP Perlscript/VBScript Order of execution
Message-Id: <1106787763.935857.295330@z14g2000cwz.googlegroups.com>

Out of curiostiy, why be so rude? If perhaps this question was better
directed at a different newgroup. why not try to be helpful and, dare I
say, polite?
Certainly you must have better ways to direct your angst than at first
time posters who are simply seeking information.



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

Date: Thu, 27 Jan 2005 03:01:52 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: ASP Perlscript/VBScript Order of execution
Message-Id: <AQYJd.218$Eh5.72@trnddc04>

LinnAxis wrote:
> Out of curiostiy, why be so rude?

Whom are you talking to and what do you consider to be rude?
It would be nice (not to mention standard practise) to provide some context.

> If perhaps this question was better

Which question? Your posting doesn't contain any question and doesn't 
reference any question either.

> directed at a different newgroup. why not try to be helpful and, dare
> I say, polite?

You reap what you sow.
If you would have had the minimal standard politeness of reading this NG for 
at least a week before contributing your own posting then you would have 
noticed that non-Perl questions are very much frowned upon in this 
community.

> Certainly you must have better ways to direct your angst than at first
> time posters who are simply seeking information.

Being polite to someone who violates the most basic rules of nettiquette may 
be a virtue, but only very few people are saints, in particular if it 
happens for the gazillionth time.

jue 




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

Date: 26 Jan 2005 19:36:40 -0800
From: "LinnAxis" <janschiffman@hotmail.com>
Subject: Re: ASP Perlscript/VBScript Order of execution
Message-Id: <1106797000.664312.109370@f14g2000cwb.googlegroups.com>

I was the poster of the original question in this thread.
I was referring to Tad McClellen .
This is a newgroup, not a way of life.

"violates the most basic rules of nettiquette" - a bit heavy handed for
a newgroup posting.

This thread bores me so I will continue no further.
Clearly there are many people in this world who need distractions
outside of the net.

Regards.



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

Date: 27 Jan 2005 01:02:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 6.17 Why don't word-boundary searches with "\b" work for me?
Message-Id: <ct9eig$c3b$1@mamenchi.zrz.TU-Berlin.DE>

brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:
> In article <ct91l4$49q$2@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel
> <anno4000@lublin.zrz.tu-berlin.de> wrote:
> 
> > Ah, classes...  The misconceptions you get to see there are carefully
> > guided misconceptions. Some are even of didactical value.  Tame
> > misconceptions, in a word.  The FAQ must fight the wild (grrrr)
> > misconceptions that grow in the jungles script kiddies mistake for
> > their minds.
> 
> I realize that.  I just wonder what Peter has run into. I beleive
> Tom or Nat wrote the answer when they were both teaching Perl, so
> they might drawing on their classroom experience too.
> 
> Are the misconceptions in the faq the ones that you have run
> into in the wild?

Not really.  Mostly I see people expect "word" to mean whatever they
happen to understand by the term, and a failure to understand that
\b is zero-width.

Anno


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

Date: Thu, 27 Jan 2005 00:09:06 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: how do u convert a string to a date
Message-Id: <kqVJd.6153$Sl3.148022@news4.e.nsc.no>

colin_lyse wrote:
> have a file with the following lines (total of 50)
> 
> I. 12/16 22:33:17. <thread 1.5>: Ready to handle requests
> E. 01/11 18:29:12. <thread 1.1>: Ready to handle requests
> I. 01/12 11:29:12. <thread 1.2>: Ready to handle requests
> I. 01/12 13:29:12. <thread 1.3>: Ready to handle requests
> E. 01/26 19:29:12.<Main>: Error: [-10002] ODBC: [Microsoft] ODBC Driver
> I. 01/26 19:29:12. <thread 1.5>: Ready to handle requests
> 
> what i need to do is for dates and times within the last hour fine any line 
> with E.

I think the 'Time::Local' module will do the job on this one;


   #!/usr/bin/perl
   #
   use strict;
   use warnings;
   use Time::Local;

   use constant SECONDS_IN_HOUR => 60 * 60;

   my $now  = time;
   my $year = (localtime)[5] + 1900;

   while ( <DATA> ) {
       if ( m,^E\. (\d+)/(\d+) (\d+):(\d+):(\d+), ) {
           my $time = timelocal( $5, $4, $3, $2, $1 - 1, $year );
           print if ( ($now - $time) < SECONDS_IN_HOUR );
       }
   }

You might want to "calculate" $now and $year inside that 'while' 
statement if you're piping to the script, though.


-- 
Tore Aursand <tore@aursand.no>
"To cease smoking is the easiset thing I ever did. I ought to know,
  I've done it a thousand times." (Mark Twain)


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

Date: Wed, 26 Jan 2005 23:52:00 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how do u convert a string to a date
Message-Id: <A2WJd.44381$Qb.43729@edtnps89>

colin_lyse wrote:
> using perl on Win2k box
> 
> 
> have a file with the following lines (total of 50)
> 
> I. 12/16 22:33:17. <thread 1.5>: Ready to handle requests
> E. 01/11 18:29:12. <thread 1.1>: Ready to handle requests
> I. 01/12 11:29:12. <thread 1.2>: Ready to handle requests
> I. 01/12 13:29:12. <thread 1.3>: Ready to handle requests
> E. 01/26 19:29:12.<Main>: Error: [-10002] ODBC: [Microsoft] ODBC Driver
> I. 01/26 19:29:12. <thread 1.5>: Ready to handle requests
> 
> what i need to do is for dates and times within the last hour fine any line 
> with E.
> 
> what i looking for is how to convert the timestamp in the line to an actual 
> timestamp i can compare to the localtime.  have seen lots of info on 
> converting dates to string but not other way around

That is all you need to do:


my @date = localtime time - 3600;  # one hour ago
my $today = sprintf '%02d/%02d', $date[ 4 ] + 1, $date[ 3 ];
my $last_hour = sprintf '%02d:%02d:%02d', @date[ 2, 1, 0 ];
my $curr_hour = sprintf '%02d:%02d:%02d', ( localtime )[ 2, 1, 0 ];


while ( <FILE> ) {

     my ( $status, $date, $time ) = m|^(\w)\.\s+([\d/]+)\s+([\d:]+)|;

     print if $status eq 'E' and $date eq $today and $time gt $last_hour and 
$time lt $curr_hour;

     }



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 26 Jan 2005 19:22:33 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Old tutorial - now corrected
Message-Id: <slrncvggip.2al.tadmc@magna.augustmail.com>

binnyva@hotmail.com <binnyva@hotmail.com> wrote:


> Can we concentrate on my tutorial, please?


That would be a waste of effort.

You are not qualified to do what you are doing, please
stop doing it.


No code is *better* than bad code!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 26 Jan 2005 23:56:11 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl error
Message-Id: <v6WJd.827$u45.708@trnddc08>

quartet wrote:
> I meant attribute.

Did you mean Perl attribute or attribute error?
At least that's the only two possibilities I can find based on the subject 
and body of your posting.

Might be good to provide some context about what you are talking about, too, 
instead of just throwing 5 words into the NG.

jue 




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

Date: Thu, 27 Jan 2005 00:44:50 GMT
From: "Doug Wells" <doug@taperedsquare.com>
Subject: Regex for finding email addresses inside text file
Message-Id: <6QWJd.54$h_.2135@news.uswest.net>

Can anyone help me with a regex that looks through an entire text file
which might have multiple email addresses in it, and writes those email
addresses out to a second file?

Thanks for the help
Doug


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

Date: Wed, 26 Jan 2005 20:08:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regex for finding email addresses inside text file
Message-Id: <slrncvgj9h.2al.tadmc@magna.augustmail.com>

Doug Wells <doug@taperedsquare.com> wrote:

> Can anyone help me with a regex 


Sure.

Show us the regex in question, and we will help you fix it.


> that looks through an entire text file
> which might have multiple email addresses in it, and writes those email
> addresses out to a second file?


Regexes do not read/write files.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 27 Jan 2005 03:07:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regex for finding email addresses inside text file
Message-Id: <EVYJd.224$Eh5.74@trnddc04>

Doug Wells wrote:
> Can anyone help me with a regex that looks through an entire text file
> which might have multiple email addresses in it, and writes those
> email addresses out to a second file?

You may want to read the FAQ "How do I check a valid mail address?".

While in theory using REs to identify email addresses may be possible, just 
like parsing HTML no sane person would try to do it that way.

jue 




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

Date: 26 Jan 2005 18:11:59 -0800
From: "Tuc" <google@ttsg.com>
Subject: Regexp kicking my ass
Message-Id: <1106791919.491987.267950@z14g2000cwz.googlegroups.com>

Hi,

I'm trying to get a regexp to make a match, and its not working,
and its kicking my ass. The text I'm going against is :

$text='<div id="sr_SearchResultsPageNavTop">   <div
id="sr_SaveSearchImage"><img
src="http://images.match.com/match//search/sr_NavIconPlaceHolder.gif"
width="15
" height="12" alt="" border="0"></div> <div
id="sr_ViewPhotoGalleryText"><a
href="come.aspx?sid=A1065D66-8275-47BE-85F2-AC161E2D6D26&theme=214&trackingid=0
&RN=2102522&lid=7&PN=1&DO=2" class="cssGlobalLinks_PageNav"
id="lnkSaveThisSearch">viewas photo gallery</a></div>     <div
id="sr_Pagination"><span
class="cssGlobalSysText_LightGray">page&nbsp;</span><a
href="some.aspx?sid=A1065D66-8275-47BE-85F2-AC161E2D6D26&theme=214&trackingid=0&RN=2102522&lid=8&PN=1&DO=0"
class="cssSr_PaginationCurrentPage" id="lnkPage">1</a><a
href="come.aspx?sid=A1065D66-8275-47BE-85F2-AC161E2D6D26&theme=214&trackingid=0&RN=2102522&lid=8&PN=2&DO=0"class="cssSr_PageNav"
id="lnkPage">2</a><a
href="come.aspx?sid=A1065D66-8275-47BE-85F2-AC161E2D6D26&theme=214&trackingid=0&RN=2102522&lid=8&PN=3&DO=0"
class="cssSr_PageNav" id="lnkPage">';

What I'm looking for is the url between the href and
cssSr_PaginationCurrentPage  .  When I do it, it ends ip starting at
the first href and going all the way to the
cssSr_PaginationCurrentPage. I've tried \b, I've tried {}, I tried
()'s.... And I just can't get it to get the one url of
some.aspx?sid=A1065D66-8275-47BE-85F2-AC161E2D6D26&theme=214&trackingid=0&RN=2102522&lid=8&PN=1&DO=0

How am I to tell it to start at the cssSr_PaginationCurrentPage
and work backwards to the first instance of href="


      Thanks, Tuc



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

Date: Wed, 26 Jan 2005 21:41:43 -0500
From: Bob Walton <see_sig@invalid>
Subject: Re: Regexp kicking my ass
Message-Id: <41f85573$1_1@127.0.0.1>

Tuc wrote:
 ...
> I'm trying to get a regexp to make a match, and its not working,
> and its kicking my ass. The text I'm going against is :
> 
 ... [HTML snipped]

> 
> What I'm looking for is the url between the href and
> cssSr_PaginationCurrentPage  .  When I do it, it ends ip starting at
> the first href and going all the way to the
> cssSr_PaginationCurrentPage. I've tried \b, I've tried {}, I tried
> ()'s.... And I just can't get it to get the one url of
> some.aspx?sid=A1065D66-8275-47BE-85F2-AC161E2D6D26&theme=214&trackingid=0&RN=2102522&lid=8&PN=1&DO=0
> 
> How am I to tell it to start at the cssSr_PaginationCurrentPage
> and work backwards to the first instance of href="
> 

Maybe if you showed us the regexp we could comment on it.  There 
is one thing that can be said about it without seeing it:  Using 
regexp is not a good way to parse HTML.  Parsing HTML is much 
more difficult that it looks like at first glance.  Use a module, 
maybe HTML::Parser.

>       Thanks, Tuc
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: 26 Jan 2005 17:01:42 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Why does glob() work in while loop?
Message-Id: <b893f5d4.0501261701.627c0e03@posting.google.com>

Dear Perl community,

   I was recently explaining to a friend new to Perl about while loop
conditions and how they implictly assign a value to $_ only if the
condition looks like:

      while (<HANDLE>)

and not like:

      while (function())

   To demonstrate an incorrect example, I executed this following code
that contains glob() in the while condition:


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

while (glob("*"))
{
   print "$_\n";
}
__END__


   I was surprised to see that the program worked as expected!  (That
is, it listed every file in my directory.)  I didn't expect it to do
that, because I didn't think that the while condition would populate
$_ for me.

   I played around a little more, and came up with a new script:


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

{
   my $num = 0;

   sub getNextNum
   {
      return ++$num;
   }
}

while (getNextNum())
{
   print "$_\n";
   sleep(1);
}
__END__


   Instead of calling the glob() function in the while condition, the
getNextNum() function is called, which just returns an integer (the
first time it is called, it returns 1; every other time, it returns a
number one greater than the previous call).

   Now, when I run this program, those new to Perl might expect that
the return value gets put in $_ and then gets printed out.  Instead, I
get:

Use of uninitialized value in concatenation (.) or string at ... line
16.

which makes sense to me, because I know that the return value of
getNextNum() is never placed in $_.

   But if the return value of getNextNum() is not placed in $_, then
doesn't that mean that the return value of glob() also should not be
placed in $_?  If my reasoning is correct, why does the first program
I gave populate $_?

   Thanks in advance for any explanations.

   -- Jean-Luc


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

Date: Wed, 26 Jan 2005 22:12:10 -0500
From: Bob Walton <see_sig@invalid>
Subject: Re: Why does glob() work in while loop?
Message-Id: <41f85c98$1_1@127.0.0.1>

J. Romano wrote:
 ...
>    I was recently explaining to a friend new to Perl about while loop
> conditions and how they implictly assign a value to $_ only if the
> condition looks like:
> 
>       while (<HANDLE>)
> 
> and not like:
> 
>       while (function())
> 
>    To demonstrate an incorrect example, I executed this following code
> that contains glob() in the while condition:
> 
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> while (glob("*"))
> {
>    print "$_\n";
> }
> __END__
> 
> 
>    I was surprised to see that the program worked as expected!  (That
> is, it listed every file in my directory.)  I didn't expect it to do
> that, because I didn't think that the while condition would populate
> $_ for me.
> 
>    I played around a little more, and came up with a new script:
> 
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> {
>    my $num = 0;
> 
>    sub getNextNum
>    {
>       return ++$num;
>    }
> }
> 
> while (getNextNum())
> {
>    print "$_\n";
>    sleep(1);
> }
> __END__
> 
> 
>    Instead of calling the glob() function in the while condition, the
> getNextNum() function is called, which just returns an integer (the
> first time it is called, it returns 1; every other time, it returns a
> number one greater than the previous call).
> 
>    Now, when I run this program, those new to Perl might expect that
> the return value gets put in $_ and then gets printed out.  Instead, I
> get:
> 
> Use of uninitialized value in concatenation (.) or string at ... line
> 16.
> 
> which makes sense to me, because I know that the return value of
> getNextNum() is never placed in $_.
> 
>    But if the return value of getNextNum() is not placed in $_, then
> doesn't that mean that the return value of glob() also should not be
> placed in $_?  If my reasoning is correct, why does the first program
> I gave populate $_?
 ...
>    -- Jean-Luc

Well, it works that way because Perl was coded that way, I 
suppose.  You can use Deparse to see what Perl compiles it to:

D:\junk>perl -MO=Deparse -e "while(<*>){print}"
use File::Glob ();
while (defined($_ = glob('*'))) {
     print $_;
}
-e syntax OK

D:\junk>perl -MO=Deparse -e "while(glob('*')){print}"
use File::Glob ();
while (defined($_ = glob('*'))) {
     print $_;
}
-e syntax OK

D:\junk>perl -MO=Deparse -e "while(xxx('*')){print}"
while (xxx('*')) {
     print $_;
}
-e syntax OK

The Perl compiler is pretty smart.  Even hiding a while() as a 
for(;;) doesn't fool it:

D:\junk>perl -MO=Deparse -e "for(;<*>;){print}"
use File::Glob ();
while (defined($_ = glob('*'))) {
     print $_;
}
-e syntax OK

Basically, the <...> syntax is an alias for glob(...), and the 
special case for the while loop is checked for after the alias is 
processed, so as not to mess things up for those who prefer 
glob() over its angle-bracket alias.  I don't know the history, 
but I assume glob() came first, and <> was added later to make 
things nicer?  The defined($_=glob(...)) bit was a relatively 
recent addition -- one used to have to code that explicitly if 
one wanted proper while loop behavior in all cases.

HTH.
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: Thu, 27 Jan 2005 03:17:29 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Why does glob() work in while loop?
Message-Id: <41f85c86.189044741@news.erols.com>

jl_post@hotmail.com (J. Romano) wrote:

: #!/usr/bin/perl
: use strict;
: use warnings;
: 
: while (glob("*"))
: {
:    print "$_\n";
: }
: __END__
: 
: 
:    I was surprised to see that the program worked as expected!  (That
: is, it listed every file in my directory.)  I didn't expect it to do
: that, because I didn't think that the while condition would populate
: $_ for me.

[snip]

:    But if the return value of getNextNum() is not placed in $_, then
: doesn't that mean that the return value of glob() also should not be
: placed in $_?  If my reasoning is correct, why does the first program
: I gave populate $_?

This is explained in the documentation for the glob function.  It's got a
splash of DWIM built in.



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

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 V10 Issue 7698
***************************************


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