[22056] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4278 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 18 06:05:40 2002

Date: Wed, 18 Dec 2002 03:05:09 -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, 18 Dec 2002     Volume: 10 Number: 4278

Today's topics:
    Re: comparing mangled times perlistically! (qanda)
    Re: Delete series of bit sequences 1A1A from end of fil <goldbb2@earthlink.net>
        eval + SIGPIPE = exitcode ? <pilsl_use@goldfisch.at>
    Re: extract dir name from file path <N.Hirani@hgmp.mrc.ac.uk>
    Re: Extracting Strings Matching a Regular Expression <bart.lateur@pandora.be>
    Re: ExtUtils::MakeMaker: installing scripts to sbin? (Paul Cody Johnston)
    Re: ExtUtils::MakeMaker: installing scripts to sbin? <tassilo.parseval@post.rwth-aachen.de>
    Re: FTPing without Net::FTP <BROWNHIK@Syntegra.Bt.Co.Uk>
    Re: getstore not working - please help (Helgi Briem)
    Re: members area in perl ??? <mbudash@sonic.net>
        mkdir -p <sgrover@quicklogic.com>
    Re: Net::SMTP error <bart.lateur@pandora.be>
        Perl websites ? <hujirong888@hotmail.com>
    Re: Perl websites ? <sunil_franklin@hotmail.com>
    Re: Perl websites ? (Helgi Briem)
    Re: PerlCE on PocketPC (brian)
    Re: scripting advice?  perl + sh <goldbb2@earthlink.net>
    Re: Simple Regex <goldbb2@earthlink.net>
    Re: using perl to download wsj.com pages , with user id <jurgenex@hotmail.com>
    Re: using perl to download wsj.com pages , with user id <mgjv@tradingpost.com.au>
    Re: using perl to download wsj.com pages , with user id <uri@stemsystems.com>
    Re: Whee, a new JAPH (David Combs)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 18 Dec 2002 01:02:39 -0800
From: fumail@freeuk.com (qanda)
Subject: Re: comparing mangled times perlistically!
Message-Id: <62b4710f.0212180102.44fe7c5@posting.google.com>

Thanks for the replies all.

This kind of response is perfect (maybe for all newcomers to all
languages) especially when learning as a second (or nth!) language. 
It immediately gives solid independant solutions that can be compared
to see similarities and language-isms; idioms if that sounded funny :)

Thanks again.

To answer Benjamin ...

Why?  The timelocal() function can parse such dates, I think.
> # T is delimter between date and time.
I need to read about the timelocal function more, I didn't think it
could handle that kind of format.

If the date is a fixed length string, then why is this needed?
The field format using the T (and even crazier record format) is
defined elsewhere, we just have to deal with it :(


And for John ...
 
> >     while( <DATA> ) {
> >         my @flds = split( /,/, $_, -1 );
>                                ^^^^^^^^
> Where do people learn this stuff?  :-)
Sorry, I'm not sure what you mean (spaces?), can you explain.

> >         my $f1_time = scalar(timelocal(
> >                 substr( $f1_times[$i], 12,2 ),
> >                 substr( $f1_times[$i], 10,2 ),
> >                 substr( $f1_times[$i], 8,2 ),
> >                 substr( $f1_times[$i], 6,2 ),
> >                 substr( $f1_times[$i], 4,2 ),
> 
> You have an error here.
> 
> >                 substr( $f1_times[$i], 2,2 ) ));
> 
> And a potental error here
> 
> >         my $f2_time = scalar(timelocal(
> >                 substr( $f2_times[$i], 12,2 ),
> >                 substr( $f2_times[$i], 10,2 ),
> >                 substr( $f2_times[$i], 8,2 ),
> >                 substr( $f2_times[$i], 6,2 ),
> >                 substr( $f2_times[$i], 4,2 ),
> 
> Same error here.  You are passing the human readable month number (1-12)
> to timelocal but it is expecting a range of 0-11.
> 
> >                 substr( $f2_times[$i], 2,2 ) ));
> 
> You are passing the last two digits of the year to localtime.  This
> _should_ work (it does on my computer) but it might fail for some dates.
> 
Thanks for pointing that out.


Thanks to both of you for the examples, I'll be studying them
intently!


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

Date: Wed, 18 Dec 2002 00:30:05 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Delete series of bit sequences 1A1A from end of file.
Message-Id: <3E0007DD.2645242D@earthlink.net>

Patrick Flaherty wrote:
> 
> Hi,
> 
> As an artifact of the software that we use to span our old and new
> systems (software = PATHworks, old system = VMS, new system =
> Windows), we get an artifact at the end of VMS text files (at some
> point opened and then saved from Windows) where there are word-aligned
> series of the sequence 1A1A at the end of the file (my ASCII table
> tells me that 1A is SUB whatever that means).
> 
>   So it seems to reasonable to:
> 
>   1) open the file
>   2) spin backwards
> while
>  3) recognizing 1A1A and deleting them (does this require having a
> separate output stream?)
>   4) close the file (with the garbage sequences deleted).

If these \x1A characters are only at the end of the file, a better
solution would be:

   1) open the file for read/write.
   2) seek() to one word-length short of the end of the file.
   3) read the last word's worth of bytes from the file.
   4) truncate() the file just before the \x1A characters.

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

die "Usage: $^X -S $0 FILENAME(s)\n" unless @ARGV;

my $successes = 0;

FILE: foreach my $filename (@ARGV) {

   my $w = sub {
      warn("Couldn't @_ $filename: $!.  Skipping\n");
      next FILE;
   };

   open( my ($fh), "<+", $filename ) or $w->("open");

   my $s = -s $fh or ++$successes, next FILE;
   $s -= ( $s % 4 ) || 4; # back up so as to be word-aligned.

   seek( $fh, $s, 0 ) or $w->("seek through");

   my $lastbytes = do { local $/; <$fh> };
   $lastbytes =~ /\x1A/ or ++$successes, next FILE;
   $s += $-[0];

   truncate( $fh, $s ) or $w->("truncate");
   ++$successes;
}

print "$successes files successfully shortened\n";

__END__
[untested]

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Wed, 18 Dec 2002 10:49:29 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: eval + SIGPIPE = exitcode ?
Message-Id: <3e0044d1$1@e-post.inode.at>


I need to trap a timeout and a 'broken pipe' and use the recommended 
eval-statement combined with change of SIG-handlers.

Things work almost perfect, but the total exitcode of my script seems to be 
wrong to me.

I trap the "broken pipe" and continue my script and finish with 'exit 0;' 
Nevertheless the perlscript returns a nonzero exitcode and prints out the 
"broken pipe"-error and so the calling programm detects an error.

$./t1.pl && echo ok || echo bad
it occured to me that a pipe just happend
continue with daily work
Broken pipe
bad
 
the script:

===========================================
#! /usr/bin/perl -w
use strict;
 
my $timeout=5;
$|=1;
 
open (FH,'/tmp/bad');
 
eval {
  local $SIG{ALRM} = sub { die "alarm\n" };
  local $SIG{PIPE} = sub { die "pipe\n" };
  alarm $timeout;
 
  if (open (DH,'| /usr/sbin/sendmail -f x@goldfisch.at y@goldfisch.at')) {
    while (my $line=<FH>) {print DH $line;}
    close DH;
  }
  alarm 0;
};
 
if ($@) { # time out
  my $err=$@; $err=~s/\n//;
  print "it occured to me that a $err just happend\n";
 
}
else { # ok
  print "worked well\n";
}
 
close FH;
print "continue with daily work\n";
 
exit 0;
========================================


 
thnx,
peter

ps: of course the mainquestion remains, why my '/tmp/bad' makes sendmail 
closing unexpected when called within perl. If I pipe the file to sendmail 
in bash things work perfect ... 
/tmp/bad is a mail that went through our server and caused lot of troubles.
Its a difficult mail (containing lots of other mails as attachments) but 
that doesnt explain why sendmail closes when invoked within perl and works 
perfect when invoked via bash. But thats a different topic and 
unfortunately I cant post the mail.


-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Wed, 18 Dec 2002 09:42:02 +0000
From: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
Subject: Re: extract dir name from file path
Message-Id: <3E0042EA.AE5F4258@hgmp.mrc.ac.uk>

Thanks guys.
All the suggestions have been very helpful.
In my case I know I'm on unix so portability and other finesse is not
necessary
thus I have gone for the simpler solution of using a simple RE.

Happy holidays.

Naran.

Naran Hirani wrote:

> Hi,
>
> I'm sure there is a very simple solutions to this but I can't seem to
> work it out :-)
> I have a fully qualified path name to a file which may or may not have
> an extension
> - all I would like to do is strip away the file name so I am left with
> just the dir path to
> this file.  What is the simplest RE that will achieve this for me?
>
> TIA
> Naran.



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

Date: Wed, 18 Dec 2002 11:00:02 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Extracting Strings Matching a Regular Expression
Message-Id: <0sk00vo44sj22vk8nb5kleo4keerdn9f7l@4ax.com>

Hal Vaughan wrote:

>But is there any way, using a regex or search and replace that I can extract 
>that zip+4 from the line of text?  For example, I tried:
>
>$line =~ s/^.*[0-9]{5}-[0-9]{4}.*$/[0-9]{5}-[0-9]{4}/g;
>
>but it takes the target string literally.

This is regexes 101. Use capturing, with parenthese.

	$line =~ /([0-9]{5}-[0-9]{4})/;

and you'll see the captured ZIP code in the special variable $1, also on
the replacement side of a s///. This extends unlimited, for example in 

	$line =~ /(([0-9]{5})-([0-9]{4}))/;
	          ^^        ^ ^        ^^
This will also capture the opening 5 digits in $2, and the closing 4
digits in $3. Count with me (see in a fixed pitch font): 

	          ^<-        $1       ->^
	           ^<- $2 ->^
	                      ^<- $3 ->^

So it's what's between balanced parentheses that is captured, whether
nested or side by side, and to know which match you get where, count the
opening parens starting from the left.

-- 
	Bart.


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

Date: 17 Dec 2002 23:30:41 -0800
From: pcj-google@inxar.org (Paul Cody Johnston)
Subject: Re: ExtUtils::MakeMaker: installing scripts to sbin?
Message-Id: <9d4ea49.0212172330.25fb3310@posting.google.com>

brian d foy <comdog@panix.com> wrote in message news:<171220021812209387%comdog@panix.com>...
> In article <9d4ea49.0212171337.556f7028@posting.google.com>, Paul Cody
> Johnston <pcj-google@inxar.org> wrote:
> 
> > $ perl Makefile.PL INSTALLSCRIPT=/usr/sbin
>  
> > But of course that puts the onus on the user to put things in the
> > right place.  Does there not exist the notion of a system binary
> > directory in MakeMaker?
> 
> 
> you can put that directly in your WriteMakefile:
> 
> WriteMakefile(
>  
>    ...
> 
>    'INSTALLSCRIPT' => '/usr/sbin',
> 
>    ...   
>    );
> 
> you may want consider prompting the user for an installation
> location, then putting it where the user wants.

Excellent points.  Another question: is there a way to access PREFIX
from inside the WriteMakefile script?  I can think of a way using
Data::Dumper, but it would not be the most straightforward solution.


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

Date: 18 Dec 2002 08:32:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: ExtUtils::MakeMaker: installing scripts to sbin?
Message-Id: <atpbrr$9ee$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Paul Cody Johnston:

> brian d foy <comdog@panix.com> wrote in message news:<171220021812209387%comdog@panix.com>...
>> In article <9d4ea49.0212171337.556f7028@posting.google.com>, Paul Cody
>> Johnston <pcj-google@inxar.org> wrote:
>> 
>> > $ perl Makefile.PL INSTALLSCRIPT=/usr/sbin
>>  
>> > But of course that puts the onus on the user to put things in the
>> > right place.  Does there not exist the notion of a system binary
>> > directory in MakeMaker?
>> 
>> 
>> you can put that directly in your WriteMakefile:
>> 
>> WriteMakefile(
>>  
>>    ...
>> 
>>    'INSTALLSCRIPT' => '/usr/sbin',
>> 
>>    ...   
>>    );
>> 
>> you may want consider prompting the user for an installation
>> location, then putting it where the user wants.
> 
> Excellent points.  Another question: is there a way to access PREFIX
> from inside the WriteMakefile script?  I can think of a way using
> Data::Dumper, but it would not be the most straightforward solution.

If you want to find out the default PREFIX at runtime, you could use the
Config module that returns all the settings that were compiled into your
perl-executable:

    use Config;
    print $Config{prefix};

See 'perldoc Config' for a long list of all the queryable keys and their
meaning.

If you want to set it, you simply use

    WriteMakefile(
        ...
        PREFIX => '/path',
        ...
    );

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Wed, 18 Dec 2002 10:50:57 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: FTPing without Net::FTP
Message-Id: <atpkai$g4l$1@pheidippides.axion.bt.co.uk>


"Cold Cathoid" <mememe@meme.com> wrote in message
news:atnosi$vo82$1@ID-158028.news.dfncis.de...
> Hi all,
>
> I am looking to write a perl script that does a rather simple task. I need
> to ftp a directory of files from a remote server. The remote server
requires
> a login and password. I did some research and the Net::FTP would be really
> handy. Unfortunently it's not installed on the box I am using. I talked to
> our sysadmin and he said he could install it ... one day ... he figures in
a
> couple months he could get around to it. It's not high on his list of
> priorities.
>
> That being said I was wondering if anyone could point me in another
> direction. When it's all said and done what I need to do is copy a folder
of
> files from a remote directory to a local directory (local to the perl
> script). Any thoughts?
>
> Thanks in advance.
>
> --
> "I don't apologize. I'm sorry, but that's just the way I am."
> - Homer Simpson
>
>

# This will work for Unix

$cmd = "'open $HOSTNAME\\nuser $USER $PASSWORD\\nasc\\ncd $REMDIR\\nlcd
LOCALDIR\\nget $filename\\nquit\\n'";

@res = `echo $cmd | /usr/bin/ftp -ivn`;
############################################################################
########################
# This works for DOS/Windows

$cmd = <<EOC;
open $HOSTNAME
user $USER $PASSWORD
asc
lcd $LOCALDIR
cd $REMDIR
get $filename
quit
EOC

open (FIL, '>c:\\temp.ftp');
print (FIL $cmd);
close FIL;

@res = `ftp -ivns:c:\\temp.ftp`;
unlink 'c:\\temp.ftp';




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

Date: Wed, 18 Dec 2002 09:35:50 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: getstore not working - please help
Message-Id: <3e004112.1171569117@news.cis.dfn.de>

On 17 Dec 2002 18:45:16 -0800, newsgroups@bandwood.com
(Dennis Macdonald) wrote:

>Below is the code that I'm using. The status returned is OK but
>nothing is downloaded. Can anyone help me with why and how to fix it.
>
>use LWP::Simple;
>use HTTP::Status;
>
>my $remote="http://www.bandwood.com/_testdir/winzip.zip";
>my $local="winzip.zip";
>my $rc = &getstore($remote,$local);
>if ($rc != RC_OK) { print status_message($rc), "\n"; }
>print ("#########\n");
>print ("Download Status = " . status_message($rc). "\n");
>print ("#########\n");

Works fine for me.  Are you sure you know where 
it is putting winzip.zip?  

Try giving it an explicit path.

Make sure that your proxy settings are correct (if you
use a proxy/firewall).
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Wed, 18 Dec 2002 05:13:31 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: members area in perl ???
Message-Id: <mbudash-E672D7.21133017122002@typhoon.sonic.net>

In article <Xns92E7F09B8676Acontrol153NOSPAMyaho@167.206.3.2>,
 opt cool dude <control153@NOSPAMyahoo.com> wrote:

> what i mean .. i have seen many tutorials on creating a members area in php  
> (eg: http://www.devarticles.com/art/1/241) using php + mysql with sessions
> but i have not seen one for perl .... is something like this possible to do 
> in perl ??? 
> thanks 
> newbee here 
> 

of course it's possible - it'd use the same technology as php: session 
id's and/or cookies


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

Date: Wed, 18 Dec 2002 16:23:06 +0530
From: Sandeep Grover <sgrover@quicklogic.com>
Subject: mkdir -p
Message-Id: <3E005392.2030802@quicklogic.com>

Hi,

I am using
`mkdir -p a/b/c/d`
to create a directory a/b/c/d, where a, b, c
are also not exisint.. -p switches creates
the hierarchical directories.

This command when executed on shell is working fine
but when invoked thru perl doesnt !

Can anyone tell me what I am doing wrong ?
Also does perl's native mkdir provides support
for -p switch in any case ?

Regards
Sandeep
-- 
"C is quirky, flawed and an enormous success"
       ^^^^^^
-- Dennis Ritchie



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

Date: Wed, 18 Dec 2002 11:01:40 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Net::SMTP error
Message-Id: <eal00v8eg186qkl70k5pbjj1s8iip9u7qf@4ax.com>

Andrew Burton wrote:

>[error]
>Can't call method "mail" on an undefined value at ./testmail.pl line 10.
>[/error]
>
>I've searched through Google, and come up with a couple of things that could
>have been the problem, yet when I modified/changed them I kept getting the same
>error.

In general, this means you don't have an object. Your "new" method
returned undef. You'll have to check why that happens.

-- 
	Bart.


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

Date: Wed, 18 Dec 2002 14:16:17 +0800
From: "Hu Ji Rong" <hujirong888@hotmail.com>
Subject: Perl websites ?
Message-Id: <atp3a4$1c0$1@reader01.singnet.com.sg>

I am new to Perl, but not programming. What are the best website for Perl?
Like JavaWorld for java.
Thanks,
JiRong




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

Date: Wed, 18 Dec 2002 13:55:00 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Re: Perl websites ?
Message-Id: <xkWL9.1$Md.92@news.oracle.com>

"Hu Ji Rong" <hujirong888@hotmail.com> wrote in message
news:atp3a4$1c0$1@reader01.singnet.com.sg...
> I am new to Perl, but not programming. What are the best website for Perl?
> Like JavaWorld for java.
> Thanks,
> JiRong
>
>

    Some of the sites I visit.
http://www.perldoc.com/
http://www.perl.org/
http://www.perlmonks.org






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

Date: Wed, 18 Dec 2002 09:40:37 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Perl websites ?
Message-Id: <3e0041b9.1171736117@news.cis.dfn.de>

On Wed, 18 Dec 2002 13:55:00 +0530, "Sunil"
<sunil_franklin@hotmail.com> wrote:

>"Hu Ji Rong" <hujirong888@hotmail.com> wrote in message
>news:atp3a4$1c0$1@reader01.singnet.com.sg...
>> I am new to Perl, but not programming. What are the best website for Perl?
>> Like JavaWorld for java.

>    Some of the sites I visit.
>http://www.perldoc.com/
>http://www.perl.org/
>http://www.perlmonks.org

Not to mention the following, which are *very* useful:

http://search.cpan.org
http://www.stonehenge.com/merlyn/columns.html
http://www.activestate.com/Products/ActivePerl/
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: 17 Dec 2002 21:55:36 -0800
From: briantac@hotmail.com (brian)
Subject: Re: PerlCE on PocketPC
Message-Id: <6b52e5a7.0212172155.6e4d9e7@posting.google.com>

Jeff Zucker <jeff@vpservices.com> wrote in message news:<3DFB7B62.5090002@vpservices.com>...
> Has anyone got perl working on a pocketPC?  Any tips for me?  I'm 
> looking to test DBI::PurePerl from my new handheld toy. With DBI and 
> DBI::proxy and the built in WiFi card, it may graduate from being a toy. 
>         But first I need to figure out how to install perl.

Well I just got it successfully installed, make sure you visit
http://www.rainer-keuchel.de/wince/perlce.html --get perlce, perlIDE,
and desktop tools for ce
and use the sample batch file to append the registry. Anyway I just
untarred the perlce from the above site, use the arm version if you
are running msppc, follow the directions on the site, use the batch
file in conjunction with cereg.exe, go here and get the registry
editor so you can tweak anything you messed up on the batch file. test
it all out with PerlIDE. I also have apachece installed and my scripts
are running fine if a bit slow. FYI I'm just a newbie at this ce
stuff, but I'll help where I can since I just suffered thru this.


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

Date: Wed, 18 Dec 2002 01:36:17 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: scripting advice?  perl + sh
Message-Id: <3E001761.F5748CDC@earthlink.net>

Alan wrote:
> 
> hi
> 
> we're writing a perl script to install an app which uses a 'tailored'
> shell script -- the shell script is run at boot.  That is, sections of
> the shell script must be adjusted to suit the platform.  The shell
> script is roughly 500 lines, and the tailored bit of ~15 lines follows
> the header, about 50 lines in.  I'd appreciate advice on the most
> maintainable way to create the shell script.

What is it that the shell script does, that cannot be done with perl?

Keep in mind that perl can set environment variables via %ENV.

[snip]
> The perl script could of course create the whole shell script, but
> that means that any bugfixing/changes of the shell script are made
> "once-removed" -- the snag to embedding the entire shell script in the
> perl is the extra complexity of quoting.

That's what q[], qq[], and <<HEREDOC are good for.

[snip]
> any thoughts on the cleanest approach please?  Is there a Better Way?
> alan

Do it all in perl, and none of it in shell.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Wed, 18 Dec 2002 01:03:14 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Simple Regex
Message-Id: <3E000FA2.4BB8B2DE@earthlink.net>

Jason Quek wrote:
> 
> Hi
> 
> To get the value between the first 2 'a's, I do this:
> 
> #------------------------------------
> $string = 'a monkey a cat a dolphin a';
> $string =~ /a([^a]*)a/;
> print $1;
> #------------------------------------
> 
> However, if 'a's weren't a single character, for example:
> 
> #------------------------------------
> $string = 'dog monkey dog cat dog dolphin dog';
> #------------------------------------
> 
> $string =~ /dog([^###]*)dog/;
> 
> What should I be using in place of ###?

Either:

   my ($match) = $string =~ /dog(.*?)dog/;
   print $match, "\n";

or:

   my ($match) = $string =~ /dog((?:(?!dog).)*)dog/;
   print $match, "\n";

Should do the trick.  The first uses non-greedy matching, the second
uses greedy matching with a negative lookahead qualifyer.

PS: Don't use dollar-digit variables unless you *know* that the regex
matched.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Wed, 18 Dec 2002 05:33:45 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: using perl to download wsj.com pages , with user id and password
Message-Id: <ZMTL9.43549$_S2.3992@nwrddc01.gnilink.net>

Martien Verbruggen wrote:
> On 17 Dec 2002 19:37:32 -0800,
> R Solberg <flateyjarbok@yahoo.com> wrote:
>> $folder="C:\\My Documents\\WSJDaily01\\";
>
> $folder = "c:/My Documents/WSJDaily01/";

If you are picky then do it all the way:

    $folder = 'c:/My Documents/WSJDaily01/';

SCNR ;-)

jue




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

Date: Wed, 18 Dec 2002 19:00:00 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: using perl to download wsj.com pages , with user id and password
Message-Id: <slrnb00ao0.aid.mgjv@martien.heliotrope.home>

On Wed, 18 Dec 2002 05:33:45 GMT,
	Jürgen Exner <jurgenex@hotmail.com> wrote:
> Martien Verbruggen wrote:
>> On 17 Dec 2002 19:37:32 -0800,
>> R Solberg <flateyjarbok@yahoo.com> wrote:
>>> $folder="C:\\My Documents\\WSJDaily01\\";
>>
>> $folder = "c:/My Documents/WSJDaily01/";
> 
> If you are picky then do it all the way:
> 
>     $folder = 'c:/My Documents/WSJDaily01/';

If I'm going to be picky, then I should ask: Why? :)

If I was realy picky, I'd advise the OP not to hardcode paths at all,
but to put them in configuration files, and to code with File::Spec. :)

Martien
-- 
                        | 
Martien Verbruggen      | Little girls, like butterflies, need no
                        | excuse - Lazarus Long
                        | 


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

Date: Wed, 18 Dec 2002 05:11:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: using perl to download wsj.com pages , with user id and password
Message-Id: <x7el8fud24.fsf@mail.sysarch.com>

>>>>> "AM" == Andras Malatinszky <nobody@dev.null> writes:

  >> er, then try getting:
  >> https://online.wsj.com/wsjra/servlet/WSJAuthReg?URI=%2Fdocuments%2Fmktind
  >> ex.htm%3Fdiaries.htm
  >> hth-
  >> 

  AM> Also, notice that what wsj.com is using is not basic authorization, so
  AM> saying

  AM> $req->authorization_basic('userid', 'password');

  AM> is not going to magically get you in (even if I assume that you have a
  AM> valid userid and password).

  AM> What you have instead is a web form that your script needs to be able
  AM> to fill out correctly.

  AM> perldoc -q submission

i recently wrote a crawler and used the wsj for a test page. it uses
cookies after a form is sent with the user/pw. so it is a 3 fetch
process for the first time and LWP doesn't do it for you.

first fetch of the page gets the form redirection.

fetch the form and fill it out. a cookie is set.

then fetch the original page with the cookie.

fetches after that with the cookie should all work fine.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 18 Dec 2002 06:13:38 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: Whee, a new JAPH
Message-Id: <atp3mi$l73$1@reader1.panix.com>

In article <3DF17213.19C927A3@earthlink.net>,
Benjamin Goldberg  <goldbb2@earthlink.net> wrote:
>Rafael Garcia-Suarez wrote:
>> 
>> Benjamin Goldberg wrote in comp.lang.perl.misc :
>> > The only thing that worries me in this is that I'm not sure
>> > how bad it is to fiddle with $^H, instead of use re 'eval'.
>> 
>> It's BAAAAAAAAAAAAAAAD.
>> (OTOH Abigail already wrote a $^H-based japh. So...)
>
>Actually, she wrote a number of them; look in:

It's a he.  (But you probably already know that,
               and are using the "she" just for grins
               re the "obvious" (to Americans) gender
               "implied" by the name (U.K. perhaps).)

David



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

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.  

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 4278
***************************************


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