[22731] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4952 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 7 09:07:41 2003

Date: Wed, 7 May 2003 06:05:10 -0700 (PDT)
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, 7 May 2003     Volume: 10 Number: 4952

Today's topics:
    Re: @Array - making it null (Anno Siegel)
    Re: @Array - making it null (Helgi Briem)
        accept() -> "Interrupted System Call" <spam@nospam.com>
    Re: Can't Create Text Files, Config problem (Tad McClellan)
    Re: Can't Create Text Files, Config problem <flavell@mail.cern.ch>
    Re: Design Opinions - Dealing with Constants <temp1_NO_SPAM_@williamc.com>
    Re: foolproof requires <spamtrap@nowhere.com>
    Re: forcing downloads <beable+unsenet@beable.com.invalid>
    Re: How do you create a biniary file in Perl. <josef.moellers@fujitsu-siemens.com>
        How does perl make differences? (i5513)
    Re: How does perl make differences? (Anno Siegel)
    Re: Locking and updating files... <krahnj@acm.org>
        Patern problem <kderaedt@hotmail.com>
    Re: Patern problem <noreply@gunnar.cc>
    Re: Patern problem <john.thetenant-s@moving-picture.com>
    Re: Patern problem (Tad McClellan)
    Re: Patern problem <kderaedt@hotmail.com>
    Re: Patern problem <noreply@gunnar.cc>
    Re: perl compiler for win32 platform? <a@b.c>
    Re: RegExp Puzzle <thomas.haselberger@ucpmorgen.com>
    Re: RegExp Puzzle (Jay Tilton)
    Re: RegExp Puzzle (Anno Siegel)
    Re: RegExp Puzzle (Anno Siegel)
    Re: RegExp Puzzle <simon.oliver@nospam.umist.ac.uk>
    Re: RegExp Puzzle (Anno Siegel)
        web page contents into a perl script <nospam@spamfreeland.com>
    Re: web page contents into a perl script <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: web page contents into a perl script <nospam@spamfreeland.com>
    Re: web page contents into a perl script <jurgenex@hotmail.com>
    Re: web page contents into a perl script <spamtrap@nowhere.com>
    Re: web page contents into a perl script (Helgi Briem)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 7 May 2003 10:39:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: @Array - making it null
Message-Id: <b9anpp$2rq$3@mamenchi.zrz.TU-Berlin.DE>

Helgi Briem <helgi@decode.is> wrote in comp.lang.perl.misc:
> On Wed, 07 May 2003 05:08:47 GMT, Uri Guttman
> <uri@stemsystems.com> wrote:
> 
> >i am working on an 'undef is evil' presentation. it is a nasty little
> >function that is rarely needed. that is not saying the undefined value
> >is not useful - it is EXTREMELY useful. the undef function itself is
> >just not needed much, and it is very bad to use it on aggregates for the
> >above mentioned reasons.
> 
> I have done a lot of parsing of text files in my time and
> I have sometimes used undef to do this sort of thing:
> 
> my ($name,$length,$position,$quality) = split;
> 
> undef $length;
> undef $quality;
> print "name $position";
> 
> Mainly to emphasise to later maintainers exactly
> what is contained in $length and $quality if they ever
> need those.  The undefs avoid "variable used only
> once" warnings.
> 
> If I simply said:
> 
> my ($name,undef,$position,undef) = split;
> print "name $position";
> 
> Later maintainer is unclear on what is contained
> in the undefined fields of the input file, although
> I could put it in comments, I suppose.
> 
> What is your opinion of these uses of undef?
> Which is preferrable or is some other solution
> better?

If I may presume to answer for Uri here, I don't think there is any
objection to using undef() with scalars.

The use with aggregates is deprecated because it leads to
inefficiencies and, worse, seems to suggest that defined() can
be reasonably used with aggregates, which it can't.

Anno


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

Date: Wed, 07 May 2003 11:10:55 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: @Array - making it null
Message-Id: <3eb8e998.2319528255@news.cis.dfn.de>

On 7 May 2003 10:39:53 GMT, anno4000@lublin.zrz.tu-berlin.de
(Anno Siegel) wrote:

>> I have done a lot of parsing of text files in my time and
>> I have sometimes used undef to do this sort of thing:
>> 
>> my ($name,$length,$position,$quality) = split;
>> 
>> undef $length;
>> undef $quality;
>> print "name $position";

<SNIP>

>If I may presume to answer for Uri here, I don't think there is any
>objection to using undef() with scalars.
>
>The use with aggregates is deprecated because it leads to
>inefficiencies and, worse, seems to suggest that defined() can
>be reasonably used with aggregates, which it can't.

Thanks.
-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


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

Date: Wed, 7 May 2003 11:39:28 +0100
From: "David" <spam@nospam.com>
Subject: accept() -> "Interrupted System Call"
Message-Id: <Co5ua.319$dv1.75455@newsfep2-gui.server.ntli.net>

I'm a bit of a newbie at Perl, but I am trying to hack together a simple
port forwarder.
It seems to work fine under windows, but when I run it under Linux the
accept() command
occasionally fails with the error "Interrupted system call". Any idea what
this means, why
it's happening, and how to fix it?

The perl versions I am using are:
Windows: v5.8.0 built for MSWin32-x86-multi-thread
Linux: v5.8.0 built for i386-linux-thread-multi


My perl code is:
#!/usr/bin/perl

use IO::Socket::INET;
use IO::Select;
$SIG{CHLD} = sub {wait ()};


if ($#ARGV+1!=3)
{
 print ("Usage:\n");
 print ("  portforward.pl [local_port] [remote_ip] [remote_port]\n\n");
 print ("  local_port  = The port to listen on.\n");
 print ("  remote_ip   = The IP address of the machine to forward the
connection to.\n");
 print ("  remote_port = The port on the remote machine to forward the
connection to.\n\n");
 exit;
}
$| = 1;
my $s = IO::Socket::INET->new(
 LocalPort => $ARGV[0],
 Type => SOCK_STREAM,
 Reuse => 1,
 Listen => SOMAXCON
 )
 or die "$ARGV[0]: Socket could not be created. Reason: $!\n";
print ("$ARGV[0]: Listening on port $ARGV[0]\n");
while ( $c = $s->accept() or die "$ARGV[0]: Cannot accept connection.
Reason: $!\n" )
{
 print ("$ARGV[0]: Received connection.\n");
 print ("$ARGV[0]: Forking...\n");
 $pid = fork();
 die "$ARGV[0]: Cannot fork: $!" unless defined($pid);
 if ($pid == 0)
 {
  # Child Process
  print ("$ARGV[0]: Connecting to remote server: $ARGV[1]:$ARGV[2]\n");
  my $r = IO::Socket::INET->new(
   PeerAddr => $ARGV[1],
   PeerPort => $ARGV[2],
   Proto => 'tcp',
   Type => SOCK_STREAM
   )
   or die "Couldn't connect! $!";
  print ("$ARGV[0]: Connection established.\n");
  my ( $bytes, $fh );
  my $select = IO::Select->new( $c, $r );
  LOOP: while (1)
  {
   foreach $fh ( $select->can_read(10) )
   {
    last LOOP unless ( defined( $bytes = sysread( $fh, $_, 4096 )));
    last LOOP if ( $bytes == 0 );
    last LOOP unless ( defined( syswrite( ( ( fileno($fh) == fileno($c) )?
$r : $c ), $_, $bytes ) ) );
   }
  }
  close($r); close($c);
  print("$ARGV[0]: Client disconnected.\n");
  exit(0); # Child process exits when it is done.
 }
 # else 'tis the parent process, which goes back to accept()
}
close($s);
print ("$ARGV[0]: Port forwarder listening on $ARGV[0] has died");





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

Date: Wed, 7 May 2003 06:58:47 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't Create Text Files, Config problem
Message-Id: <slrnbbht7n.7bf.tadmc@magna.augustmail.com>

Jon Rees <jonnyr9@r9corporation.fsnet.co.uk> wrote:

> don't think I have access to error logs...any ideas?


   perldoc -q CGI

      How can I get better error messages from a CGI program?


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


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

Date: Wed, 7 May 2003 13:53:54 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Can't Create Text Files, Config problem
Message-Id: <Pine.LNX.4.53.0305071347190.22309@lxplus013.cern.ch>

On Wed, May 7, Jon Rees blurted out atop a fullquote [1]:

[about a CGI script]

> #!/bin/perl
>
> use warnings;
> open (BOB, ">example.txt");

Please be aware that the CGI specification does not make any ruling
about what the current directory will be when the script starts.

You really need to think carefully about where you want to write
to file from a CGI script, and consider the security implications
of what you're doing.  You almost certainly _don't_ want to have CGI
scripts scribbling into the directory where the script itself lives.

And of course the other routine advice (see the posting guidelines for
this group) about how to help Perl to help you to help yourself before
posting for assistance.

good luck

[1] http://members.fortunecity.com/nnqweb/nquote.html


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

Date: Wed, 07 May 2003 10:10:16 GMT
From: PropART <temp1_NO_SPAM_@williamc.com>
Subject: Re: Design Opinions - Dealing with Constants
Message-Id: <3EB8DAF8.73D6F5C9@williamc.com>

I put my constants in a hash with a very short name e.g. Say my
organization name was Kung Fu Inc.

I have a file called KF_constants.pl containing...

our %KF = (
	USR_REGULAR => 0,
	USR_REGISTERED => 1,
	USR_PARTNER => 2,
	USR_CUSTOMER => 3,
        etc...

and the files that use it are set up something like...

#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
use CGI::Carp qw(carpout fatalsToBrowser);
use DBI;

our ( %KF );
my $include_file = 'KF_constants.pl';
require $include_file;

 ...

and when I want to grab something it isn't a lot of overhead to get it
out of the hash. Say it's the length of a database field...

$KF{'LEN_StreetAddress'}


Now, I'm thinking that I'm probably going to want more than constants in
there, though. It would also make sense to put some general purpose
functions in one place. So the design is still evolving...

--williamc














Kevin Vaughn wrote:
> 
> Interesting....
> 
> So what did you finally decide to do?
> 
> -Kevin
> 
> "PropART" <temp1_NO_SPAM_@williamc.com> wrote in message
> news:3EB7F4B3.74FD93AA@williamc.com...
> >
> >
> > Kevin Vaughn wrote:
> > >
> > > I've created a large number of scripts that reference a single file
> > > containing all of my constants.  I named the file environment.pl.  The
> file
> > > mainly contains paths.  I include environment.pl using a "required"
> > > statement.
> > >
> > > Is this good or bad design?  I'm particularly interested in the
> downsides.
> > >
> > > Now a specific question - How do I get perl to stop giving me the error
> > > "Global symbol $constant_from_environment requires explicit package name
> at
> > > $line_number" when I have strict turned on?
> > >
> > > I'm trying to get my head around the lexical vs. package scope thing,
> but
> > > it's not coming easy for some reason.  Do I have to go through creating
> a
> > > package, or can I use "our"?
> > >
> > > -Kevin
> >
> >
> > See thread above from last night, "Including files in Perl". It covers
> > almost exactly the same problem.
> >
> > IMO it's good design, because you have all your constants in one place.
> > I'm no Perl expert, though.
> >
> > --williamc


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

Date: Wed, 07 May 2003 11:13:56 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: foolproof requires
Message-Id: <gqphbv0u1pel8bef79f96d962vahh23hsb@4ax.com>

On Wed, 7 May 2003 05:00:09 +0000 (UTC), info@analysisandsolutions.com
(Analysis&Solutions) wrote:

>Hi Eric:
>
>In <Xns9373E88ADF5E9sdn.comcast@216.166.71.239> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> writes:
>
>>That's one ugly-ass prototype.  You sure you know what you're doing?
>
>Nope!  Well, not when it comes to Perl, at least.
>
>
>>Your approach sounds overly complex.  Why not create auxiliary
>>modules that would act as wrappers, one for each language?
>
>This sounds more complex to me.
>
 .. snip..

>Wouldn't this necessitate my module being in a location acceptable to 
>%INC?  Also, this seems to eliminate the ability to dynamically call 
>different languages on the fly.

You mean @INC.

Naturally any module that you plan to use needs to be in a directory
listed in @INC.  You can alter @INC at runtime.

Eric is suggesting that you create a module for each language.  That
isn't (IMO) complex.  It is a reasonable partitioning of the problem.
That way, if you add languages you can just add a 'use' statement for
the new language module.  So, CreditCardValidationSolution.pm has a
method PrintSomeError that is appropriately defined in each subclass.
CreditCardValidationSolution::EN.pm to print in English,
CreditCardValidationSolution::GR.pm in German and so forth.

Hope that makes sense -- I have not had my coffee yet ... :-\


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

Date: 07 May 2003 18:25:25 +1000
From: Beable van Polasm <beable+unsenet@beable.com.invalid>
Subject: Re: forcing downloads
Message-Id: <ee7k93xix6.fsf@dingo.beable.com>

Marshall Dudley <mdudley@execonn.com> writes:

> Malcolm Dew-Jones wrote:
> 
> > Marshall Dudley (mdudley@execonn.com) wrote:
>
> > : I have a customer who's web site I am doing who sells ebooks.
> > : These books come in several formats, pdf, html, zip, MS reader,
> > : rocket file, Mobi file.
>
> > : The reason is that people end up purchasing the book, then
> > : during the several days it can take to read it, end up with the
> > : browser crashing or Windows crashing, or end up closing it out
> > : prematurily.  Then they are unable to finish the book, and want
> > : to get it again free.
> >
> > Not really - they paid for it didn't they - you kind of owe it to them.
> 
> If you buy a book, then lose it, do you expect the store to give you
> another copy?  In this case the cost of giving them a second copy is
> much more than the original, since the original is totally
> automated, but to give them another copy requires human
> intervention, which of course costs time and money.

But I can easily not lose a book, by sticking it in a bookshelf, 
propping up a table leg with it, leaving it in a box, all sorts
of things. I have no way of stopping Windows or a web browser from
crashing.

How about if you feed them a cookie when they buy the book, and
tie the cookie onto their IP address? Then they can get as many
reads of the book as they want for one price. Except they could
be on DHCP, so you couldn't use their IP address. But something
along those lines - they buy a cookies which allows them to read
the book as many times as they like.

Anyway, I have no idea what requirements you or your customer
have for this site, and it is pretty off topic for a Perl
newsgroup, so I'll shut up now.

cheers
Beable
-- 
    Why are General Tommy Franks and H.G. Nelson never seen in the
             same place at the same time? -- Phil Doyle
                             http://beable.com


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

Date: Wed, 07 May 2003 14:31:33 +0200
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: How do you create a biniary file in Perl.
Message-Id: <3EB8FCA5.89A348C7@fujitsu-siemens.com>

"Eric J. Roode" wrote:
> =

> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
> =

> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
> news:b9aegf$nh$1@nets3.rz.RWTH-Aachen.DE:
> =

> > Also sprach Mihai N.:
> >
> >>>     binmode F;
> >>>     print F "\n";
> >>>
> >>>     # or without binmode
> >>>     print F "\012";
> >>>
> >>> "\n" is a logical newline that gets translated into the
> respective
> >>> presentation of the underlying operating system. Such a
> translation
> >>> does not happen for "\012".
> >
> >> Warning!
> >> I just tested it on Windows and if you don't use binmode the
> result for
> >> both "\n" and "\012" is 0D 0A.
> >
> > Hmmh, nasty. So I was wrong and Xavier's and Josef's posting
> suggest
> > that things are perhaps not quite as consistent as they should be.
> > I also think that your observations violate what perlport.pod has
> to
> > say. For example here:
> >
> >     A common misconception in socket programming is that "\n" eq
> "\012"
> >     everywhere. When using protocols such as common Internet
> protocols,
> >     "\012" and "\015" are called for specifically, and the values
> of the
> >     logical "\n" and "\r" (carriage return) are not reliable.
> >
> >         print SOCKET "Hi there, client!\r\n";      # WRONG
> >         print SOCKET "Hi there, client!\015\012";  # RIGHT
> >
> > So both would result in "0D 0D 0A", no? Anyway, I don't know. I'll
> be
> > very happy if I don't have to deal with such things too often.
> =

> How can perl possibly tell the difference?
> =

> my $nl1 =3D "\012";
> my $nl2 =3D "\n";
> =

> print A "whee! $nl1";
> print A "woo-hoo! $nl2";
> =

> binmode B;
> print B "whee! $nl1";
> print B "woo-hoo!" $nl2";

My interpretation of the relevant table (2-1) in the camel book is that
"\n", when used in a print statement, will move the typewriter's
carriage down one line, no matter what is needed for that (according to
http://www.natural-innovations.com/computing/asciiebcdic.html, NL is
\017 in EBCDIC) and that "\r" will move the typewriter's carriage to the
left margin, again, no matter what is needed for that.

"\012", however, will produce a character with a decimal value of 10, no
matter what the underlying system will do with that character when it is
used in a print statement.

Since most of us speak ASCII, "\n" eq "\012", and "\r" seems to be
"\015" in both ASCII and EBCDIC. =

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: 7 May 2003 04:04:26 -0700
From: i5513@hotmail.com (i5513)
Subject: How does perl make differences?
Message-Id: <a657ec02.0305070304.6e88dc2c@posting.google.com>

Well, I'm intrigued ...

how does perl distingue $/ var from /expression$/ ?

I'd like this expression:

( |$)
Perl take $) like a var 
($| ) 
Perl take $| like a var
(\Z| ) 
is similar but not equal
How I can say "( |finish)"?

Thanks you!


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

Date: 7 May 2003 12:16:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How does perl make differences?
Message-Id: <b9ate7$7ak$2@mamenchi.zrz.TU-Berlin.DE>

i5513 <i5513@hotmail.com> wrote in comp.lang.perl.misc:
> Well, I'm intrigued ...
> 
> how does perl distingue $/ var from /expression$/ ?

Perl uses a special algorithm guess if a "$" in a regex introduces a
variable or means "end of string".  Apparently it gets right most of
the time.  If it doesn't, use "${...}" to force interpretation as a
variable.

> I'd like this expression:
> 
> ( |$)
> Perl take $) like a var 
> ($| ) 
> Perl take $| like a var
> (\Z| ) 
> is similar but not equal
> How I can say "( |finish)"?

I'm not sure what you are asking here.

Anno


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

Date: Wed, 07 May 2003 10:49:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Locking and updating files...
Message-Id: <3EB8E47F.462C19A5@acm.org>

David Scarlett wrote:
> 
> I want to delete certain lines from a file, but I'm not sure how to do
> it while keeping the file locked....
> 
> One way I could think of was to write the file to another file,
> skipping the unwanted lines, and then delete the original and rename
> the 2nd file to that of the original, however I can't see any way of
> stopping the original from being read while it's being deleted...
> 
> Or, I could make a copy of the original file, open the copy for
> reading, open the original for writing, get an exclusive lock on the
> original, and read from the copy into the original, skipping the
> unwanted lines and then truncate the original and delete the copy...
> 
> What's the best way to go about this?


This works on my (Linux) system.  YMMV

#!/usr/bin/perl
use warnings;
use strict;
use Fcntl qw/:flock :seek/;

my $file = 'test.txt';

open FILE, "+<$file" or die "Cannot open $file: $!";
open DUP,  ">&FILE"  or die "Cannot dup handle for $file: $!";
flock FILE, LOCK_EX  or die "Cannot flock $file: $!";

my $pos  = tell DUP;
my $size = -s FILE;

while ( <FILE> ) {
    if ( /line to delete/ ) {
        $size -= length;
        next;
        }
    seek DUP, $pos, SEEK_SET or die "Cannot seek on $file: $!";
    print DUP or die "Cannot print to $file: $!";
    $pos = tell DUP;
    }

truncate FILE, $size or die "Cannot truncate $file to $size bytes: $!";

__END__


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 7 May 2003 13:32:45 +0200
From: "kderaedt" <kderaedt@hotmail.com>
Subject: Patern problem
Message-Id: <3eb8eedf$0$21360$ba620e4c@reader1.news.skynet.be>

Hi,

    I have a problem with pattern problem.  I try to read some data out a
field[1] after a pattern (User-Agent:) until the end of line.  But this is
not even entering the 'if' function.

Example:
x-up-uplink: wapdemo.iplab.atea.be
x-up-subno: 1045233412-1_wapdemo.iplab.atea.be
x-up-proxy-ba-enable: 1
x-up-proxy-enable-trust: 1
Accept-Language: en
User-Agent: SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a
x-up-devcap-max-pdu: 2800
x-up-devcap-charset: utf-8
Encoding-version: 1.3

Code used:
 if ($Field[1] =~ m/"User-Agent:(.*)\n"/gi) {
   print "in loop $1\n\n ";
    $headers=$1;
 }

Should give:
SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a

Thanks

Karel




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

Date: Wed, 07 May 2003 14:02:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Patern problem
Message-Id: <b9asvl$hk852$1@ID-184292.news.dfncis.de>

kderaedt wrote:
>     I have a problem with pattern problem.  I try to read some data out a
> field[1] after a pattern (User-Agent:) until the end of line.  But this is
> not even entering the 'if' function.
> 
> Example:
> x-up-uplink: wapdemo.iplab.atea.be
> x-up-subno: 1045233412-1_wapdemo.iplab.atea.be
> x-up-proxy-ba-enable: 1
> x-up-proxy-enable-trust: 1
> Accept-Language: en
> User-Agent: SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a
> x-up-devcap-max-pdu: 2800
> x-up-devcap-charset: utf-8
> Encoding-version: 1.3
> 
> Code used:
>  if ($Field[1] =~ m/"User-Agent:(.*)\n"/gi) {
----------------------^---------------^^^-^

Provided that the data is in the second element in the array @Field, 
it should do what you want if you remove the double-quotes. Also, the 
\n character and the g modifier appears to be redundant.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 7 May 2003 13:11:10 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Patern problem
Message-Id: <20030507131110.7c814cc9.john.thetenant-s@moving-picture.com>

On Wed, 7 May 2003 13:32:45 +0200
"kderaedt" <kderaedt@hotmail.com> wrote:
>
> Hi,
> 
>     I have a problem with pattern problem.  I try to read some data out a
> field[1] after a pattern (User-Agent:) until the end of line.  But this is
> not even entering the 'if' function.
> 
> Example:
> x-up-uplink: wapdemo.iplab.atea.be
> x-up-subno: 1045233412-1_wapdemo.iplab.atea.be
> x-up-proxy-ba-enable: 1
> x-up-proxy-enable-trust: 1
> Accept-Language: en
> User-Agent: SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a
> x-up-devcap-max-pdu: 2800
> x-up-devcap-charset: utf-8
> Encoding-version: 1.3
> 
> Code used:
>  if ($Field[1] =~ m/"User-Agent:(.*)\n"/gi) {

lose the double quotes in the above, for starters.
(and, what's in $Field[0]?)

>    print "in loop $1\n\n ";
>     $headers=$1;
>  }
> 
> Should give:
> SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a
> 

show your problem output, as well.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Wed, 7 May 2003 07:35:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Patern problem
Message-Id: <slrnbbhvc1.7bf.tadmc@magna.augustmail.com>

kderaedt <kderaedt@hotmail.com> wrote:

>     I have a problem with pattern problem.

> Example:
[snip]
> User-Agent: SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a

>  if ($Field[1] =~ m/"User-Agent:(.*)\n"/gi) {
                      ^                 ^
                      ^                 ^

Your pattern requires double quotes in the string.

There are no double quotes in the string.

Match fails.


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


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

Date: Wed, 7 May 2003 14:37:44 +0200
From: "kderaedt" <kderaedt@hotmail.com>
Subject: Re: Patern problem
Message-Id: <3eb8fe19$0$21338$ba620e4c@reader1.news.skynet.be>

The @field is an array that contains a record.  $field[0] is a mobile phone
number.
The example data given is data, is data out of $field[1].
The problem is that this code is not entering the 'if'.  So I think there is
a problem with my pattern.


"kderaedt" <kderaedt@hotmail.com> wrote in message
news:3eb8eedf$0$21360$ba620e4c@reader1.news.skynet.be...
> Hi,
>
>     I have a problem with pattern problem.  I try to read some data out a
> field[1] after a pattern (User-Agent:) until the end of line.  But this is
> not even entering the 'if' function.
>
> Example:
> x-up-uplink: wapdemo.iplab.atea.be
> x-up-subno: 1045233412-1_wapdemo.iplab.atea.be
> x-up-proxy-ba-enable: 1
> x-up-proxy-enable-trust: 1
> Accept-Language: en
> User-Agent: SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a
> x-up-devcap-max-pdu: 2800
> x-up-devcap-charset: utf-8
> Encoding-version: 1.3
>
> Code used:
>  if ($Field[1] =~ m/"User-Agent:(.*)\n"/gi) {
>    print "in loop $1\n\n ";
>     $headers=$1;
>  }
>
> Should give:
> SIE-ME45/21 UP.Browser/5.0.2.1.103 (GUI) UP.Link/5.1.1.5a
>
> Thanks
>
> Karel
>
>




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

Date: Wed, 07 May 2003 14:39:44 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Patern problem
Message-Id: <b9av4l$hbbkv$1@ID-184292.news.dfncis.de>

kderaedt wrote:
> The @field is an array that contains a record.  $field[0] is a
> mobile phone number.
> The example data given is data, is data out of $field[1]. The
> problem is that this code is not entering the 'if'.  So I think
> there is a problem with my pattern.

You have already got comments on the pattern. But is it @field and
$field[1] or @Field and $Field[1] ? Case matters.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 07 May 2003 12:43:19 +0200
From: ZZT <a@b.c>
Subject: Re: perl compiler for win32 platform?
Message-Id: <b9ao07$105$1@news1.wdf.sap-ag.de>

Hello Simon,

> OK, quick summary from the PAR list is that they aren't exactly sure 
> what's going on either!  Their best guess is that you have MSVC++ 
> installed (Yes?),
correct

> and that both nmake and cl are in your path (Yes?), 
no they wasn't in my path
I download and used the nmake suggested from the makefile.pl-construct

> There are two potential fixes to this:
> 
> 1) If you want to compile PAR yourself using your local compiler then 
> run the vcvars32.bat file which comes with the PAR distribution before 
> doing perl Makefile.PL etc.  This should find all the appropriate 
> library paths for your local compiler and things should proceed from there.
this part is now running fine, but...

the whole script-creation-stuff has unfort. problems with spaces in 
path-names. I manually fixed a lot of them by editing the created files 
but in step "NMAKE TEST" I got:

Microsoft (R) Program Maintenance Utility   Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

         C:\progra~1\tools\perl\bin\perl -Ic:\progra~1\tools\perl\lib 
-Ic:\progra
~1\tools\perl\lib -MExtUtils::Command -e cp script/pp blib\script\pp
         C:\progra~1\tools\perl\bin\perl -Ic:\progra~1\tools\perl\lib 
-Ic:\progra
~1\tools\perl\lib  -e "system qq[pl2bat.bat ].shift" blib\script\pp
         C:\progra~1\tools\perl\bin\perl -Ic:\progra~1\tools\perl\lib 
-Ic:\progra
~1\tools\perl\lib -MExtUtils::Command -e cp script/par.pl blib\script\par.pl
         C:\progra~1\tools\perl\bin\perl -Ic:\progra~1\tools\perl\lib 
-Ic:\progra
~1\tools\perl\lib  -e "system qq[pl2bat.bat ].shift" blib\script\par.pl
         C:\progra~1\tools\perl\bin\perl -Mblib 
-Ic:\progra~1\tools\perl\lib -Ic:
\progra~1\tools\perl\lib -e "use Test::Harness qw(&runtests $verbose); 
$verbose=
0; runtests @ARGV;" t/0-signature.t t/1-basic.t
Using C:/TEMP/PAR-0.67/blib
t/0-signature.......'C:\Program' is not recognized as an internal or 
external co
mmand,
operable program or batch file.
t/0-signature.......dubious
         Test returned status 1 (wstat 256, 0x100)
t/1-basic...........'C:\Program' is not recognized as an internal or 
external co
mmand,
operable program or batch file.
t/1-basic...........dubious
         Test returned status 1 (wstat 256, 0x100)
FAILED--2 test scripts could be run, alas--no output ever seen
NMAKE : fatal error U1077: 'C:\progra~1\tools\perl\bin\perl' : return 
code '0x2'

Stop.


and I am not able to fix it.
I didn't found out the module which calls something in
"c:\program files..." to change the call to c:\progra~1... or add "" to 
the call.

best Regards



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

Date: Wed, 07 May 2003 12:20:14 +0200
From: Thomas Haselberger <thomas.haselberger@ucpmorgen.com>
Subject: Re: RegExp Puzzle
Message-Id: <ufznr3voh.fsf@ucpmorgen.com>

Simon Oliver <simon.oliver@nospam.umist.ac.uk> writes:

> I know this should be simple but I can't figure it out.
>
> I want to replace all occurrence of the percent symbol in a string
> with another string.  But if the percent symbol is escaped with a
> backslash I want to ignore it.  Supposing I want to replace each '%'
> with '!':

I thought this should do what you need

$a = 'agsa\%%dfdsa';
#$a = 'agsa%dfdsa';
$a =~ s/([^\\])%/\1!/g;
print $a,"\n";

but this assumption was wrong. in a series of % the re would 
only replace every second occurence of %

better try that:

$a =~ s/([^\\])(%+)/ $1 . '!' x length($2)/eg;


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

Date: Wed, 07 May 2003 10:21:12 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: RegExp Puzzle
Message-Id: <3eb8dd63.351099533@news.erols.com>

Simon Oliver <simon.oliver@nospam.umist.ac.uk> wrote:

: I want to replace all occurrence of the percent symbol in a string with 
: another string.  But if the percent symbol is escaped with a backslash I 
: want to ignore it.  Supposing I want to replace each '%' with '!':
: 
: foo%bar => foo!bar
: foo\%bar => foo%bar
: foo%%bar => foo!!bar
: foo\%%bar => foo%!bar
: 
: I suppose backslashes will need an escape too.
: 
: foo\bar => foobar
: foo\\bar => foo\bar
: foo\%bar => foo%bar
: foo\\%bar => foo\!bar
: foo\\\%bar => foo\%bar

    my %subs = (
        '%'   => '!',
        '\\%' => '%',
        '\\\\' => '\\',
        '\\' => '',
    );

    $val =~ s#(\\%|%|\\\\|\\)#$subs{$1}#eg;



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

Date: 7 May 2003 10:24:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegExp Puzzle
Message-Id: <b9amt8$2rq$1@mamenchi.zrz.TU-Berlin.DE>

Thomas Haselberger  <thomas.haselberger@ucpmorgen.com> wrote in comp.lang.perl.misc:
> Simon Oliver <simon.oliver@nospam.umist.ac.uk> writes:
> 
> > I know this should be simple but I can't figure it out.
> >
> > I want to replace all occurrence of the percent symbol in a string
> > with another string.  But if the percent symbol is escaped with a
> > backslash I want to ignore it.  Supposing I want to replace each '%'
> > with '!':
> 
> this should do what you need
> 
> $a = 'agsa\%%dfdsa';
> #$a = 'agsa%dfdsa';
> 
> $a =~ s/([^\\])%/\1!/g;
                   ^^

Use $1 on the right side of an s///, not \1.

> 
> print $a,"\n";

No, it doesn't.  Try it on "foo%%bar" (it will only replace one of the
"%"), or on "%foo" (it won't replace "%").  The reason is that your
pattern matches one character before each "%".  If there is none, it
won't match.  If there is one, it will match it and not consider it
again, even if it is a "%".

To the OP:

I'd do that in two steps.  First replace all unescaped "%" with
"!".  That can be done with "negative lookbehind"

    s/(?<!\\)%/!/g;

That will leave the backslash in front of the escaped "\%".  Clean
that up with

    s/\\%/%/g;

Anno


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

Date: 7 May 2003 10:25:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegExp Puzzle
Message-Id: <b9amvm$2rq$2@mamenchi.zrz.TU-Berlin.DE>

Thomas Haselberger  <thomas.haselberger@ucpmorgen.com> wrote in comp.lang.perl.misc:
> Simon Oliver <simon.oliver@nospam.umist.ac.uk> writes:
> 
> > I know this should be simple but I can't figure it out.
> >
> > I want to replace all occurrence of the percent symbol in a string
> > with another string.  But if the percent symbol is escaped with a
> > backslash I want to ignore it.  Supposing I want to replace each '%'
> > with '!':
> 
> I thought this should do what you need
> 
> $a = 'agsa\%%dfdsa';
> #$a = 'agsa%dfdsa';
> $a =~ s/([^\\])%/\1!/g;
> print $a,"\n";
> 
> but this assumption was wrong. in a series of % the re would 
> only replace every second occurence of %
> 
> better try that:
> 
> $a =~ s/([^\\])(%+)/ $1 . '!' x length($2)/eg;

That still requires a character in front of the first "%" to match.

Anno


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

Date: Wed, 07 May 2003 12:00:23 +0100
From: Simon Oliver <simon.oliver@nospam.umist.ac.uk>
Subject: Re: RegExp Puzzle
Message-Id: <3EB8E747.8040906@nospam.umist.ac.uk>

Anno Siegel wrote:
> 
> I'd do that in two steps.  First replace all unescaped "%" with
> "!".  That can be done with "negative lookbehind"
> 
>     s/(?<!\\)%/!/g;
> 
> That will leave the backslash in front of the escaped "\%".  Clean
> that up with
> 
>     s/\\%/%/g;
> 

Anno, that works fine - I'm not sure that the backslashes are working as a 
user might expect - in your solution the backslashes only escape percent 
symbols, so \\ without a following % results in \\ but \\% results in \%. 
  Wouldn't it be more perlish to have single backslashes always mean 
escape the following character (whether it needs it or not) unless 
preceded by backslash?

I was originally planning to use % to escape itself so:
   %%  -> %
   %   -> !
   %%% -> %!

But how could one write a string that resulted in !%
   %%% -> %! (not !%)

Thanks for your help everyone.

Here's my test script:

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

my $r = '!';

while (<DATA>) {
   chomp;
   printf '%-12s -> ', $_;
   s/(?<!\\)%/!/g;
   s/\\%/%/g;
   print "$_\n";
}

__DATA__
foo\%bar
foo%%bar
foo\%%bar
foo\bar
foo\\bar
foo\%bar
foo\\%bar
foo\
foo\\
foo\%
foo\\%
\bar
\\bar
\%bar
\\%bar

-- 
   Simon Oliver



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

Date: 7 May 2003 12:09:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegExp Puzzle
Message-Id: <b9at27$7ak$1@mamenchi.zrz.TU-Berlin.DE>

Simon Oliver  <simon.oliver@nospam.umist.ac.uk> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > 
> > I'd do that in two steps.  First replace all unescaped "%" with
> > "!".  That can be done with "negative lookbehind"
> > 
> >     s/(?<!\\)%/!/g;
> > 
> > That will leave the backslash in front of the escaped "\%".  Clean
> > that up with
> > 
> >     s/\\%/%/g;
> > 
> 
> Anno, that works fine - I'm not sure that the backslashes are working as a 
> user might expect - in your solution the backslashes only escape percent 
> symbols, so \\ without a following % results in \\ but \\% results in \%. 
>   Wouldn't it be more perlish to have single backslashes always mean 
> escape the following character (whether it needs it or not) unless 
> preceded by backslash?

If you want that behavior, use the same technique again in the second
step:

    s/(?<!\\)\\//g;

This will delete single backslashes and turn double backslashes to
single ones.  A single backslash at the end of the string will also
disappear, which is arguably wrong because there is nothing it could
escape.  I guess that can be mended too...

> I was originally planning to use % to escape itself so:
>    %%  -> %
>    %   -> !
>    %%% -> %!
> 
> But how could one write a string that resulted in !%
>    %%% -> %! (not !%)

"!%%".  If you disallow "!" in the original string, no way.

Anno


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

Date: Wed, 7 May 2003 18:03:25 +0800
From: "Ahab" <nospam@spamfreeland.com>
Subject: web page contents into a perl script
Message-Id: <3eb8d9e5$1@usenet.per.paradox.net.au>

Hi all,

How would you read  the contents of a web page into a perl script ?

Once I can get it as $_ , I can then do further stuff with it.


For instance:

http:\\www.example.com\  has a index.html. I want to read the contents of
that html page into a perl script just as I could read the contents of text
file in as $_.

Any help would be appreciated.

-- 
Ahab




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

Date: Wed, 7 May 2003 10:11:57 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: web page contents into a perl script
Message-Id: <slrnbbhmth.1uf.bernard.el-hagin@gdndev25.lido-tech>

In article <3eb8d9e5$1@usenet.per.paradox.net.au>, Ahab wrote:
> Hi all,
> 
> How would you read  the contents of a web page into a perl script ?
> 
> Once I can get it as $_ , I can then do further stuff with it.
> 
> 
> For instance:
> 
> http:\\www.example.com\  has a index.html. I want to read the contents of
> that html page into a perl script just as I could read the contents of text
> file in as $_.
> 
> Any help would be appreciated.


perldoc LWP::Simple


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Wed, 7 May 2003 18:50:44 +0800
From: "Ahab" <nospam@spamfreeland.com>
Subject: Re: web page contents into a perl script
Message-Id: <3eb8e4fc$1@usenet.per.paradox.net.au>

No documentation found for 'LWP::Simple'


-- 
Ahab




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

Date: Wed, 07 May 2003 11:00:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: web page contents into a perl script
Message-Id: <mH5ua.47204$B61.33758@nwrddc01.gnilink.net>

Ahab wrote:
> How would you read  the contents of a web page into a perl script ?
> For instance:
>
> http:\\www.example.com\  has a index.html. I want to read the
> contents of that html page into a perl script just as I could read
> the contents of text file in as $_.

Didn't the advice given in the FAQ work for you?

    perldoc -q HTML: "How do I fetch an HTML file?"

jue




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

Date: Wed, 07 May 2003 11:16:25 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: web page contents into a perl script
Message-Id: <lmqhbvonvekelahojh98njaqr75g9nsi2a@4ax.com>

On Wed, 7 May 2003 18:50:44 +0800, "Ahab" <nospam@spamfreeland.com>
wrote:

>No documentation found for 'LWP::Simple'

search.cpan.org

Have you read the posting guidelines?



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

Date: Wed, 07 May 2003 11:18:20 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: web page contents into a perl script
Message-Id: <3eb8eaff.2319887501@news.cis.dfn.de>

On Wed, 7 May 2003 18:50:44 +0800, "Ahab"
<nospam@spamfreeland.com> wrote:

>No documentation found for 'LWP::Simple'

Then you have a broken or outdated distribution
of Perl.  The libwww-perl bundle has been a core
module for a long time.  It is not worth the hassle
to use unsupported ancient software.

Get a new version of Perl.  
-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


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

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


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