[17471] in Perl-Users-Digest
Perl-Users Digest, Issue: 4891 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 15 03:07:37 2000
Date: Wed, 15 Nov 2000 00:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974275512-v9-i4891@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 15 Nov 2000 Volume: 9 Number: 4891
Today's topics:
Re: beginner question regarding extracting email body w (Chris Fedde)
Can "-e $myfile || -r $myfile" be more concise? <skylemon@ne.mediaone.net>
Re: Can "-e $myfile || -r $myfile" be more concise? (Martien Verbruggen)
Re: Can "-e $myfile || -r $myfile" be more concise? <jeffp@crusoe.net>
Re: Can "-e $myfile || -r $myfile" be more concise? (Alan Barclay)
Re: Can "-e $myfile || -r $myfile" be more concise? <dennis_marti@yahoo.com>
CGI.pm: textarea insanity <kj0@mailcity.com>
Re: CGI.pm: textarea insanity <godzilla@stomp.stomp.tokyo>
Re: CGI.pm: textarea insanity (Alan Barclay)
Re: CGI.pm: textarea insanity (Chris Fedde)
Re: Converting Troff to Jpeg (Chris Fedde)
Re: Date (Ameen Dausha)
Re: Date <tony_curtis32@yahoo.com>
Re: HTML download form - CGI/Perl (dionysus)
HTTP::Request's header code v. the true http error code <brondsem@my-deja.com>
Re: HTTP::Request's header code v. the true http error <tony_curtis32@yahoo.com>
Re: HTTP::Request's header code v. the true http error <brondsem@my-deja.com>
Re: HTTP::Request's header code v. the true http error (Martien Verbruggen)
Re: IP geography <bart.lateur@skynet.be>
Re: IP geography <bart.lateur@skynet.be>
Re: IP geography <jeff@vpservices.com>
Re: IP geography (Ilya Zakharevich)
Re: Is this possible in Perl? <bugfixxer@yahoo.com>
Re: Please tell me why this code is wrong (ActiveState (Garry Williams)
Re: Problem with chomp and print <arm@home.com>
Re: Problem with chomp and print (Martien Verbruggen)
Regex to zero pad an IP address <peter.sundstrom@eds.com>
Re: Regex to zero pad an IP address <peter.sundstrom@eds.com>
replacing strings in a file.... <didier.lefevre@elias.be>
Sort files by date jimbob4334@my-deja.com
Re: Sort files by date <wyzelli@yahoo.com>
Re: Sort files by date (Martien Verbruggen)
Re: Sort files by date (Martien Verbruggen)
Re: Sort files by date <wyzelli@yahoo.com>
Re: Sort files by date (Chris Fedde)
Re: Splitting up a regex <skylemon@ne.mediaone.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 15 Nov 2000 06:40:38 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: beginner question regarding extracting email body with regexp
Message-Id: <GdqQ5.437$Bf7.178934784@news.frii.net>
In article <slrn9138qg.dmj.damajah@kzahq.ath.cx>,
Debian User <damajah@kzahq.ath.cx> wrote:
> Now this program reads standard mailbox format files, a single message
> at a time from stdin, so I want to read from the first line following
> a line where \n is the first character up till eof.
>
Unix mailbox files use an odd delimiter between messages.
"\nFrom "
So you can put perl into "message at a time mode" with something
like this.
$/ = "\nFrom ";
while (<>)
{
print 'x'x30,"\n";
print $_;
print 'x'x30,"\n";
}
this is probably a FAQ. You might answer it yourself by looking in the
perlfaq manual page.
Good luck
--
This space intentionally left blank
------------------------------
Date: Wed, 15 Nov 2000 04:57:46 GMT
From: Sky Lemon <skylemon@ne.mediaone.net>
Subject: Can "-e $myfile || -r $myfile" be more concise?
Message-Id: <3A12419A.E0A22C7E@ne.mediaone.net>
Hello,
How do I make
-e $myfile || -r $myfile
more concise?
Best regards,
Sky Lemon
------------------------------
Date: Wed, 15 Nov 2000 16:23:05 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Can "-e $myfile || -r $myfile" be more concise?
Message-Id: <slrn9147dp.gs3.mgjv@martien.heliotrope.home>
On Wed, 15 Nov 2000 04:57:46 GMT,
Sky Lemon <skylemon@ne.mediaone.net> wrote:
> Hello,
>
> How do I make
>
> -e $myfile || -r $myfile
>
> more concise?
From the perlfunc documentation:
[snip]
If any of the file tests (or either the `stat' or
`lstat' operators) are given the special filehan
dle consisting of a solitary underline, then the
stat structure of the previous file test (or stat
operator) is used, saving a system call. (This
doesn't work with `-t', and you need to remember
that lstat() and `-l' will leave values in the
stat structure for the symbolic link, not the real
file.) Example:
print "Can do.\n" if -r $a || -w _ || -x _;
[snip other examples]
-e $myfile || -r _
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Wed, 15 Nov 2000 00:31:48 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Can "-e $myfile || -r $myfile" be more concise?
Message-Id: <Pine.GSO.4.21.0011150031190.265-100000@crusoe.crusoe.net>
[posted & mailed]
On Nov 15, Sky Lemon said:
> How do I make
>-e $myfile || -r $myfile
> more concise?
-e $myfile || -r _
perldoc perlfunc, and look for the the -X file tests.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: 15 Nov 2000 05:44:12 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Can "-e $myfile || -r $myfile" be more concise?
Message-Id: <974267019.950333@elaine.furryape.com>
In article <3A12419A.E0A22C7E@ne.mediaone.net>,
Sky Lemon <skylemon@ne.mediaone.net> wrote:
>Hello,
>
> How do I make
>
>-e $myfile || -r $myfile
-e $myfile
If the file doesn't exist, it can't be readable. Conversely, if it's
readable, it must be exist. Therefore there is no case where your second
test can be true when the first test is false, and your second test
is redundant.
------------------------------
Date: Wed, 15 Nov 2000 00:49:05 -0500
From: Dennis Marti <dennis_marti@yahoo.com>
Subject: Re: Can "-e $myfile || -r $myfile" be more concise?
Message-Id: <dennis_marti-838D1A.00490515112000@news.starpower.net>
In article <3A12419A.E0A22C7E@ne.mediaone.net>, Sky Lemon
<skylemon@ne.mediaone.net> wrote:
> How do I make
>
> -e $myfile || -r $myfile
>
> more concise?
Readable files exist, so your test is the same as
-e $myfile;
If what you really want to know is whether or not a file is readable
-r $myfile; # I'm readable therefore I am.
Dennis
------------------------------
Date: 14 Nov 2000 21:06:13 -0500
From: kj0 <kj0@mailcity.com>
Subject: CGI.pm: textarea insanity
Message-Id: <8usr2l$gp5$1@panix3.panix.com>
I have a cgi script that uses CGI.pm. The script generates a form
that includes a textarea field. Users are expected to enter words in
this textarea field, one word per line. The problem is that CGI.pm
inserts spurios white space between the indvidual words, so that if
the textarea ever needs to be redisplayed, it's a mess. For example,
if the original input by the user was
dog
cat
cow
CGI.pm mangles it into
dog
cat
cow
I.e. it replaces every new line by a new line followed by 10 spaces.
I've tried all sorts of crazy stuff, including
textarea( -name = 'this_is_hell',
-rows = 10,
-cols = 20,
-wrap = 'off',
-value = "dog\ncat\ncow",
-override = 1 )
and still friggn CGI.pm adds 10 spurious spaces after every newline.
If someone can tell me what's going on I'd be very grateful.
KJ
------------------------------
Date: Tue, 14 Nov 2000 19:14:16 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: CGI.pm: textarea insanity
Message-Id: <3A11FF88.FA64177E@stomp.stomp.tokyo>
kj0 wrote:
(snippage)
> I have a cgi script that uses CGI.pm....
> CGI.pm mangles it....
> ...and still friggn CGI.pm adds 10 spurious
> spaces after every newline.
> If someone can tell me what's going on
> I'd be very grateful.
"CGI.pm mangles it...."
Your own words well describe your problem.
Write your own read and parse routine, address
a bit of security if needed and, all your problems
instantly vanish. Only challenge for you is having
to actually program rather than rely on Cargo Cult
Copy and Paste cgi.poopmaker.
Shouldn't take more than fifteen minutes to write
a very nice read and parse which includes ample
security and addresses your input variables with
significant ease, if you know how to program.
Godzilla!
------------------------------
Date: 15 Nov 2000 05:16:41 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: CGI.pm: textarea insanity
Message-Id: <974265382.303652@elaine.furryape.com>
In article <8usr2l$gp5$1@panix3.panix.com>, kj0 <kj0@mailcity.com> wrote:
>I.e. it replaces every new line by a new line followed by 10 spaces.
>I've tried all sorts of crazy stuff, including
>
> textarea( -name = 'this_is_hell',
> -rows = 10,
> -cols = 20,
> -wrap = 'off',
> -value = "dog\ncat\ncow",
> -override = 1 )
Firstly, ignore what the resident troll says.
Secondly, that can't be your actual code. All the '=' signs should
be '=>'.
Thirdly, is the problem on the HTML output by CGI, or the data returned
by the browser? How do you know?
Please create a short test program which clearly demonstrates the problem,
and this will hopefully isolate the problem.
------------------------------
Date: Wed, 15 Nov 2000 05:48:34 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: CGI.pm: textarea insanity
Message-Id: <SspQ5.434$Bf7.190543872@news.frii.net>
The great salamander marches on Tokyo in search of baby deer..
kj0 wrote:
>
>(snippage)
>
>> I have a cgi script that uses CGI.pm....
>
>> CGI.pm mangles it....
>
>> ...and still friggn CGI.pm adds 10 spurious
>> spaces after every newline.
>
>> If someone can tell me what's going on
>> I'd be very grateful.
To which the mudpuppy responded:
>
>
>"CGI.pm mangles it...."
>
>Your own words well describe your problem.
>
#
# So I thought I'd try it out...
#
use CGI ':standard';
$t = html( body( start_form,
textarea(
-name => 'this_is_hell',
-rows => 10,
-cols => 20,
-wrap => 'off',
-value => "dog\ncat\ncow",
-override => 1
), end_form
));
print $t;
#
# http:/denver.pm.org/salamander.html
# You be the judge
#
--
This space intentionally left blank
------------------------------
Date: Wed, 15 Nov 2000 06:56:38 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Converting Troff to Jpeg
Message-Id: <GsqQ5.438$Bf7.190408704@news.frii.net>
In article <3A11B429.53EB2736@_ANTISPAM_.lucent.com>,
Jeff H <jeffahill@_ANTISPAM_.lucent.com> wrote:
>Does anyone out there know of a Perl utility that would convert a Troff file
>into a Jpeg image for web display? The Jpeg part is not especially important,
>it could be Gif or Png for all I care, as long as I can put it on a webpage.
>
>Jeff
Perl is not the best tool for everything.
man -t LWP | gs -sDEVICE=pngmono -sOutputFile=op%d.png -
Isn't unix great!
--
This space intentionally left blank
------------------------------
Date: Wed, 15 Nov 2000 02:27:48 GMT
From: ameen @ dausha . net (Ameen Dausha)
Subject: Re: Date
Message-Id: <3a11f48e.17053769@news>
The CPAN Module "Date::Manip" is plenty powerful.
On 15 Nov 2000 00:53:46 GMT, jobbey83@aol.com (JOBBEY83) spat:
>Hi, I am a total newbie and I am wondering how I can calculate the current date
>mm/dd/yy. If it involves installing a module could you please direct me on how
>to do so?
Ben Wilson (a.k.a. Ameen, Last of the Dausha)
____________________________
-"Ever heard of Aristotle . . . Plato . . . Socrates?!"
-"Yes."
-"Morons!"
------------------------------
Date: 14 Nov 2000 20:30:24 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Date
Message-Id: <878zqmotkv.fsf@limey.hpcc.uh.edu>
>> On 15 Nov 2000 00:53:46 GMT,
>> jobbey83@aol.com (JOBBEY83) said:
> Hi, I am a total newbie and I am wondering how I can
> calculate the current date mm/dd/yy. If it involves
> installing a module could you please direct me on how to
> do so?
Poisonally, I'd go for localtime() and the POSIX module:
use POSIX 'strftime';
my $datestr = strftime('%m/%d/%y', localtime);
although I might prefer %Y over %y myself.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Wed, 15 Nov 2000 07:40:16 GMT
From: dionysus39@hotmail.com (dionysus)
Subject: Re: HTML download form - CGI/Perl
Message-Id: <3a123dd1.99513783@nntp.unsw.edu.au>
got it...cheers for that :->
-d
------------------------------------------------------------
"One World, one Web, one Program" - Microsoft promotional ad
"Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .
------------------------------
Date: Wed, 15 Nov 2000 02:51:49 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: HTTP::Request's header code v. the true http error code
Message-Id: <8usto3$7iq$1@nnrp1.deja.com>
The true headers of http://www.lego.com/lzedgo.htm are:
HTTP/1.1 302 Moved Temporarily
Server: Microsoft-IIS/5.0
Date: Wed, 15 Nov 2000 02:36:54 GMT
Connection: close
Location: /lzedgo.htm?wfx2=lh2hj34l8s
For those wondering, I used http://www.delorie.com/web/headers.html to
get the header.
But in my own perl program I got a code of 200, not 302. Here's the
code I used:
$ua = new LWP::UserAgent;
$request = new HTTP::Request GET => $url;
$response = $ua->request($request);
$httpcode = $response->code();
For the majority of webpages, I get the correct code.
However, I want to get the real code. How can I easily get the true
headers?
TIA,
Dave Brondsema
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 14 Nov 2000 21:03:20 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: HTTP::Request's header code v. the true http error code
Message-Id: <8766lqos1z.fsf@limey.hpcc.uh.edu>
>> On Wed, 15 Nov 2000 02:51:49 GMT,
>> Dave Brondsema <brondsem@my-deja.com> said:
> The true headers of http://www.lego.com/lzedgo.htm are:
> HTTP/1.1 302 Moved Temporarily Server: Microsoft-IIS/5.0
> Date: Wed, 15 Nov 2000 02:36:54 GMT Connection: close
> Location: /lzedgo.htm?wfx2=lh2hj34l8s
> For the majority of webpages, I get the correct code.
> However, I want to get the real code. How can I easily
> get the true headers?
$ perldoc LWP::UserAgent
see redirect_ok()
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Wed, 15 Nov 2000 03:51:33 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: HTTP::Request's header code v. the true http error code
Message-Id: <8ut184$a9s$1@nnrp1.deja.com>
In article <8766lqos1z.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >> On Wed, 15 Nov 2000 02:51:49 GMT,
> >> Dave Brondsema <brondsem@my-deja.com> said:
>
> > The true headers of http://www.lego.com/lzedgo.htm are:
> > HTTP/1.1 302 Moved Temporarily Server: Microsoft-IIS/5.0
> > Date: Wed, 15 Nov 2000 02:36:54 GMT Connection: close
> > Location: /lzedgo.htm?wfx2=lh2hj34l8s
>
> > For the majority of webpages, I get the correct code.
> > However, I want to get the real code. How can I easily
> > get the true headers?
>
> $ perldoc LWP::UserAgent
>
> see redirect_ok()
I get this error:
Can't call method "method" on an undefined value at
C:/perl/site/lib/LWP/UserAgent.pm line 371.
I added:
print $ua->redirect_ok();
$ua is a new LWP::UserAgent
So I looked at UserAgent.pm and found this:
sub redirect_ok
{
# draft-ietf-http-v10-spec-02.ps from www.ics.uci.edu, specify:
#
# If the 30[12] status code is received in response to a request
using
# the POST method, the user agent must not automatically redirect
the
# request unless it can be confirmed by the user, since this might
change
# the conditions under which the request was issued.
my($self, $request) = @_;
return 0 if $request->method eq "POST"; # line 371
1;
}
so I changed my code to
print $ua->redirect_ok($request);
But this function doesn't look like it really does anything useful to
me.
> hth
> t
> --
> Eih bennek, eih blavek.
>
--
Dave Brondsema
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 15 Nov 2000 15:39:42 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: HTTP::Request's header code v. the true http error code
Message-Id: <slrn9144se.gs3.mgjv@martien.heliotrope.home>
On Wed, 15 Nov 2000 03:51:33 GMT,
Dave Brondsema <brondsem@my-deja.com> wrote:
> In article <8766lqos1z.fsf@limey.hpcc.uh.edu>,
> Tony Curtis <tony_curtis32@yahoo.com> wrote:
>>
>> $ perldoc LWP::UserAgent
>>
>> see redirect_ok()
>
> I get this error:
>
> Can't call method "method" on an undefined value at
> C:/perl/site/lib/LWP/UserAgent.pm line 371.
>
> I added:
> print $ua->redirect_ok();
> $ua is a new LWP::UserAgent
>
> So I looked at UserAgent.pm and found this:
Did you also look at the documentation?
# man LWP::UserAgent
[snip]
$ua->redirect_ok
This method is called by request() before it tries to
do any redirects. It should return a true value if a
redirect is allowed to be performed. Subclasses might
want to override this.
The default implementation will return FALSE for POST
request and TRUE for all others.
[snip]
In other words, subclass LWP::UserAgent, and define your own
redirect_ok().
#!/usr/local/bin/perl -wl
use strict;
package MYUA;
use LWP::UserAgent;
@MYUA::ISA = qw(LWP::UserAgent);
sub redirect_ok { 0 }
package main;
use HTTP::Request;
my $ua = MYUA->new() or die;
my $req = HTTP::Request->new(GET => 'http://www.lego.com/lzedgo.htm');
my $resp = $ua->request($req);
print $resp->code();
__END__
Martien
--
Martien Verbruggen |
Interactive Media Division | The gene pool could use a little
Commercial Dynamics Pty. Ltd. | chlorine.
NSW, Australia |
------------------------------
Date: Wed, 15 Nov 2000 02:12:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: IP geography
Message-Id: <f7s31tcb031pc1ptt8n1q3tg6oe6q5nfvg@4ax.com>
Martien Verbruggen wrote:
>> I guess when IPv6 rolls out, early in the 31st century (no, that isn't
>> a typo), each planet, station, moon, asteroid, etc, will get its own
>> set of subnets.
>
>There's enough room in that address space to individually address each
>organ in everyone's body :)
Ooh, that's not enough. I'll be satisfied only if there are enough IP
addresses for every cell in everybody's body.
--
Bart.
------------------------------
Date: Wed, 15 Nov 2000 02:15:25 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: IP geography
Message-Id: <4es31tk8p1u6ci7sgubebl6cluqm0dfg0g@4ax.com>
Eli the Bearded wrote:
>knowing 30% of your demographic is better than known none
If only you knew which 30% you can locate.
--
Bart.
------------------------------
Date: Tue, 14 Nov 2000 18:30:56 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: IP geography
Message-Id: <3A11F560.73A29BEA@vpservices.com>
Bart Lateur wrote:
>
> Martien Verbruggen wrote:
>
> >> I guess when IPv6 rolls out, early in the 31st century (no, that isn't
> >> a typo), each planet, station, moon, asteroid, etc, will get its own
> >> set of subnets.
> >
> >There's enough room in that address space to individually address each
> >organ in everyone's body :)
>
> Ooh, that's not enough. I'll be satisfied only if there are enough IP
> addresses for every cell in everybody's body.
Bah, wimps! I want one for every nucleotide in every strand of human
DNA. Yeah, that's the ticket.
--
Jeff
------------------------------
Date: 15 Nov 2000 02:52:18 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: IP geography
Message-Id: <8ustp2$4l8$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
<mgjv@tradingpost.com.au>],
who wrote in article <slrn913lma.gs3.mgjv@martien.heliotrope.home>:
> > knowing 30% of your demographic is better than known none
>
> As long as everyone fully understands that you only know that few, and
> as long as it is possible to reliably identify the reliable 30% :)
And as long as these 30% are representative (which they are not ;-).
Ilya
------------------------------
Date: Wed, 15 Nov 2000 10:53:05 +0300
From: "Andrew Tkachenko" <bugfixxer@yahoo.com>
Subject: Re: Is this possible in Perl?
Message-Id: <3a124101.0@news.crtc.spb.ru>
Yes, that's quite easy :)
Johan Augustsson <johan.augustsson@adm.gu.se> ïèøåò â
ñîîáùåíèè:3A1156EC.4AFEE376@adm.gu.se...
> Can I do the following with Perl?
>
> Take some specific data from a logfile (which changes every now and
> then) and put it into a table in a MySQL-database. As soon as the
> logfile is updated with new data I want some of the data to get into my
> table in the database.
>
> Johan
>
>
------------------------------
Date: Wed, 15 Nov 2000 03:32:40 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Please tell me why this code is wrong (ActiveState build 613 on Winblows)
Message-Id: <stnQ5.549$xb1.31638@eagle.america.net>
On Tue, 14 Nov 2000 23:32:28 GMT, David Steuber
<nospam@david-steuber.com> wrote:
>garry@ifr.zvolve.net (Garry Williams) writes:
>' On Tue, 14 Nov 2000 17:06:27 -0500, Jeff Pinyan <jeffp@crusoe.net>
>' wrote:
>' >On Nov 14, dsteuber@my-deja.com said:
>' >
>' >>my %foo_hash = { bar => "baz" };
>
>This is a typo. My original script used:
>
>my %foo_hash = (); # different name actually
>
>And then added key/value pairs to it. Oh well.
>
>' >This is incorrect. You want (...) instead of {...}. Next time,
>' >run Perl with the -w switch turned on.
>'
>' Not sure why you think this wasn't done, but it will make no
>' difference. The code will compile without any warnings. However, at
>' *run time*, it will generate the warning "Reference found where
>' even-sized list expected at...", if warnings are enabled. The
>' original poster's code never made it to run time due to the compile
>' time error that you correctly explained.
>
>The problem, as pointed out by others, was a missing -> operator.
>Once I caught that, I tried to cancel the post, but not all servers
>honor that.
You are quoting me here but, of course, I also pointed out the error
that you complained about further down in my original post. I was
responding to the run with `-w' comment that made it seem like that
would catch the typo above *at compile time*.
As to the typo, you can probably see that it is important to cut and
paste actual code here, so people don't debug phantom problems.
>I made sure to pick up a good supply of arrows at the drug store ;-).
>
>Does ActiveState Perl work with the -w option in the script?
This is from the perlrun manual page that comes with ActiveState perl:
The #! line is always examined for switches as the line is
being parsed. Thus, if you're on a machine that allows only
one argument with the #! line, or worse, doesn't even
recognize the #! line, you still can get consistent switch
behavior regardless of how Perl was invoked
>NT is
>set up to run a .pl file with the Perl interpreter automatically.
Which is irrelevant according to perlrun.
>If
>you look at my original script, the -w was in the #! line.
Which is exactly why I posted my comment above.
>But that
>would likely as not be ignored by ActiveState.
Not according to the manual page ActiveState distributes with perl.
Just so you understand what *my* comment was, here's your typo at
compile time *with* -w and at run time with -w:
$ cat x
#!/usr/local/bin/perl -w
use strict;
my %foo_hash = { bar => "baz" };
$ perl -c x
x syntax OK
$ perl x
Reference found where even-sized list expected at x line 3.
$
There is *no* warning generated at compile time for your incorrect
assignment. Since further down in the same program there was a fatal
compile time error due to the failure to run to the drug store, there
could have never been a warning about the first error. Jeff Pinyan
admonished you to use -w to catch that (which you actually did), but
it wouldn't have caught it anyway since your script never made it to
run time.
(Jeesh! It wouldn't have caught it anyway since you transcribed it
wrong in the first place and there really wasn't *any* problem there.
All this for lack of cutting and pasting.)
>Then again, earlier runs before I got to this point would spew
>warnings when appropriate, so I think they are on. I will be hacking
>away at it again tomorrow.
In perl 5.6.0, it seems to be the preference to `use warnings;'
instead of the -w switch. Anyway, either one will work on Windows as
well as Unix.
--
Garry Williams
------------------------------
Date: Wed, 15 Nov 2000 04:02:29 GMT
From: Alan <arm@home.com>
Subject: Re: Problem with chomp and print
Message-Id: <3A120A1E.429153CE@home.com>
Thank you very much. One additional question:
field 2 because it is a day can be 31 or 1 or 4
and field 1 is a month a can be 8 or 12.
Both can throw the line off by one character
or even two characters if January 5 as opposed
to October 12 i.e.
10 31 2000 0-07-244047-3 1 103.95 103.95
10 31 2000 0-321-08503-5 1 64.70 64.70
10 31 2000 0-911910-29-8 1 32.15 32.15
10 31 2000 0-7931-3519-2 1 34.50 34.50
10 31 2000 0-13-085967-2 1 41.20 41.20
11 1 2000 0-02-804049-X 1 9.10 9.10
11 1 2000 0-07-007481-X 1 23.15 23.15
11 1 2000 0-02-804046-5 1 31.70 31.70
11 1 2000 0-7638-0236-0 1 46.30 46.30
how can I compensate.
Bart Lateur wrote:
> Alan Melton wrote:
>
> Am I close? right on
>
> chomp(@a =<IN>); # chomp all at once, once and for all
> for(my $i = 10; $i < @a; $i += 7) {
> @vals= (@a[1..3], (@a[$i .. $i+5])[0, 3..5]);
> print "@vals\n" if $vals[3];
> }
>
> >How do I perform a next unless a certain field has a value
> >or skip if there is no value in that field and go to the next record.
>
> As above, or with "next":
>
> for(my $i = 10; $i < @a; $i += 7) {
> @vals= (@a[1..3], (@a[$i .. $i+5])[0, 3..5]);
> next unless $vals[3];
> print "@vals\n";
> }
>
> >Also, the last two fields are numeric and can be 4, 5 or 6 characters
> >(dollar amounts)
> >but I want them right justified as the final result
> >should printf or sprintf come into play here and how
>
> Yes. You need a sprintf '%8.2f', $val[$i] for each of the numbers, for
> example. Example:
>
> for(my $i = 10; $i < @a; $i += 7) {
> @vals= (@a[1..3, $i, $i+3],
> map { sprintf '%8.2f', $_ } @a[$i+4, $i+5]);
> next unless $vals[3];
> print "@vals\n";
> }
>
> --
> Bart.
------------------------------
Date: Wed, 15 Nov 2000 15:47:54 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Problem with chomp and print
Message-Id: <slrn9145bq.gs3.mgjv@martien.heliotrope.home>
[Please, in the future, put your reply _after_ the suitably trimmed text
you reply to. It makes the whole thread easier to follow, and conforms
to the generally accepted posting conventions here]
On Wed, 15 Nov 2000 04:02:29 GMT,
Alan <arm@home.com> wrote:
> Thank you very much. One additional question:
> field 2 because it is a day can be 31 or 1 or 4
> and field 1 is a month a can be 8 or 12.
> Both can throw the line off by one character
> or even two characters if January 5 as opposed
> to October 12 i.e.
>
> 10 31 2000 0-13-085967-2 1 41.20 41.20
> 11 1 2000 0-02-804049-X 1 9.10 9.10
>
> how can I compensate.
Either by using printf or sprintf, just as was done for the price, or by
using a format, as I suggested in another part of this thread.
You did read the documentation on all the suggested features, once you
were aware of them, right?
From Bart's code, which you quoted upside down:
>>'
>> Am I close? right on
>>
>> chomp(@a =<IN>); # chomp all at once, once and for all
>> for(my $i = 10; $i < @a; $i += 7) {
>> @vals= (@a[1..3], (@a[$i .. $i+5])[0, 3..5]);
>> print "@vals\n" if $vals[3];
>> }
Hmm.. I like a solution with splice better. Easier on the calculus lobe.
I think the 3 @vals values here are the first three values on a line,
which I now understand to be a 4 digit year, a month number and a day
number.
printf "%4d %2d %2d", @vals if $vals[3];
They'll be right-justified.
But really, this is exactly what formats were put in Perl for in the
first place.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Wed, 15 Nov 2000 15:05:37 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Regex to zero pad an IP address
Message-Id: <8usr7c$vh1$1@hermes.nz.eds.com>
I'm playing around (with not much success) with a regex to convert a
standard IP address into a zero padded format.
Eg:
192.1.10.1
becomes
192.001.010.001
Is a regex the best way to approach it?
------------------------------
Date: Wed, 15 Nov 2000 15:14:19 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Regex to zero pad an IP address
Message-Id: <8usrno$79$1@hermes.nz.eds.com>
Peter Sundstrom <peter.sundstrom@eds.com> wrote in message
news:8usr7c$vh1$1@hermes.nz.eds.com...
> I'm playing around (with not much success) with a regex to convert a
> standard IP address into a zero padded format.
>
> Eg:
>
> 192.1.10.1
>
> becomes
>
> 192.001.010.001
>
> Is a regex the best way to approach it?
I am hanging my head in shame. I somehow seemed to be blind to the FAQ. I
ended up using:
#!/usr/local/bin/perl -w
use strict;
my $ip='10.1.20.0';
my $newip=sprintf("%03d.%03d.%03d.%03d",split(/\./,$ip));
print "ip $ip\n";
print "newip $newip\n";
------------------------------
Date: Wed, 15 Nov 2000 08:58:47 +0100
From: Didier Lefevre <didier.lefevre@elias.be>
Subject: replacing strings in a file....
Message-Id: <3A124237.80900@elias.be>
hello,
Anyone an idea on how to replace a string by another one in a file
(iside a perl program)?? Ok, I'll probably find it in one or more doc
pieces but I don't have much time to read heaps of documentation at this
moment, so...
------------------------------
Date: Wed, 15 Nov 2000 04:41:14 GMT
From: jimbob4334@my-deja.com
Subject: Sort files by date
Message-Id: <8ut45a$cid$1@nnrp1.deja.com>
I found this to find the oldest file
my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
I could not find enough info to figure how to find the newest file.
If someone would take some time to explain what the -M and -1 do I
would appreciate it.
TIA,
Jim
--
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 15 Nov 2000 14:35:20 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Sort files by date
Message-Id: <eLoQ5.14$OQ.4781@vic.nntp.telstra.net>
<jimbob4334@my-deja.com> wrote in message
news:8ut45a$cid$1@nnrp1.deja.com...
> I found this to find the oldest file
>
> my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
>
>
> I could not find enough info to figure how to find the newest file.
>
> If someone would take some time to explain what the -M and -1 do I
> would appreciate it.
>
The -1 refers to the last element of the array @files.
If that is the oldest file after the sort of the array, the logically
the first element (element 0) would be the newest.
from perlfunc:
-M Age of file in days when script started.
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Wed, 15 Nov 2000 16:07:46 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Sort files by date
Message-Id: <slrn9146h2.gs3.mgjv@martien.heliotrope.home>
On Wed, 15 Nov 2000 04:41:14 GMT,
jimbob4334@my-deja.com <jimbob4334@my-deja.com> wrote:
> I found this to find the oldest file
>
> my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
>
> I could not find enough info to figure how to find the newest file.
>
> If someone would take some time to explain what the -M and -1 do I
> would appreciate it.
You can find documentaiton on -M in the perlfunc manual pages.
Documentation on the -1 index to arrays is described in perldata.
What that stuff above does is sort your list of files by 'the age of the
file when the script started', and takes the last element of that list.
It could have reversed the whole result, and taken the first element, or
reversed the result of the sort: The following three are equivalent in
outcome, but not in speed:
$oldest = (sort {-M $a <=> -M $b} @files)[-1];
$oldest = (sort {-M $b <=> -M $a} @files)[0];
$oldest = (reverse sort {-M $a <=> -M $b} @files)[0];
I would prefer the first, which is the one you have. The reasons are
that addign a reverse just slows things down, and I tend to like sort
subs where the $a and $b are compared in that order.
Conversely, to get the newest:
$newest = (sort {-M $a <=> -M $b} @files)[0];
$newest = (sort {-M $b <=> -M $a} @files)[-1];
$newest = (reverse sort {-M $a <=> -M $b} @files)[-1];
and in this case, I prefer the first, for the same reasons.
Please, do read the perlfunc and perldata documentation. The above
examples show three ways in which you could have answered your question:
1 - understand how sort subs work (perlfunc:sort)
2 - understand how lists can be reversed (perlfunc:reverse)
3 - understand the indexing of arrays and lists (perldata)
Martien
--
Martien Verbruggen |
Interactive Media Division | life ain't fair, but the root
Commercial Dynamics Pty. Ltd. | password helps. -- BOFH
NSW, Australia |
------------------------------
Date: Wed, 15 Nov 2000 16:20:30 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Sort files by date
Message-Id: <slrn91478u.gs3.mgjv@martien.heliotrope.home>
On Wed, 15 Nov 2000 14:35:20 +0930,
Wyzelli <wyzelli@yahoo.com> wrote:
><jimbob4334@my-deja.com> wrote in message
> news:8ut45a$cid$1@nnrp1.deja.com...
>>
>> my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
>
> The -1 refers to the last element of the array @files.
Mind the brackets. The -1 refers to the last element of the sorted list.
Unless @files is already sorted, those are most likely not the same :)
Martien
--
Martien Verbruggen |
Interactive Media Division | This matter is best disposed of from
Commercial Dynamics Pty. Ltd. | a great height, over water.
NSW, Australia |
------------------------------
Date: Wed, 15 Nov 2000 15:16:52 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Sort files by date
Message-Id: <ampQ5.17$OQ.4899@vic.nntp.telstra.net>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn91478u.gs3.mgjv@martien.heliotrope.home...
> >> my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
> >
> > The -1 refers to the last element of the array @files.
>
> Mind the brackets. The -1 refers to the last element of the sorted
list.
> Unless @files is already sorted, those are most likely not the same :)
>
Yeah, I saw that, and cancelled my post, and then read your excellent
answer before correcting mine, so I didn't bother to re-do it...
You must've been quick! :)
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Wed, 15 Nov 2000 06:06:16 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Sort files by date
Message-Id: <sJpQ5.436$Bf7.189812736@news.frii.net>
In article <8ut45a$cid$1@nnrp1.deja.com>, <jimbob4334@my-deja.com> wrote:
>I found this to find the oldest file
>
>my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
>
>
>I could not find enough info to figure how to find the newest file.
>
>If someone would take some time to explain what the -M and -1 do I
>would appreciate it.
>
>TIA,
>
>Jim
>
-M is a file test that returns the file modify date.
$file[-1] is the last element of the array.
BTW this is not a problem that requires a sort.
@file = <*>;
$o = $file[0];
for $f (@file)
{
$o = $f if ( -M $f > -M $o)
}
print "$o\n";
Of course if you were shooting for a low golf score you might try this:
-M>-M$o and$o=$_ for(<*>);print"$o\n"
chris
--
This space intentionally left blank
------------------------------
Date: Wed, 15 Nov 2000 04:55:24 GMT
From: Sky Lemon <skylemon@ne.mediaone.net>
Subject: Re: Splitting up a regex
Message-Id: <3A12410C.F1CCD311@ne.mediaone.net>
Martin,
Hmmm.. I wonder if you can try backslah escaping a newline character... I
haven't tried it out myself. Even if that works you need to do something about
all the spaces in preceding what you want to match, and that could make thing
s just as messy... You could compromise for something like:
if ($_ =~ /^(Number of events|\
nBytes|\
Total Real time|\
Total CPU time|\
Max Agent time)/x
)
Best regards,
Sky Lemon
Martin Julian DeMello wrote:
> I have a piece of code that needs to trigger on lines starting with certain
> strings.
>
> Right now I'm using
>
> if (($_ =~ /^(Number of events|Total CPU time|Max Agent time)/)) { }
>
> which works nicely. However, I can't manage to split it up so that there's
> only one string per line (for readability's sake; I need to add more cases
> and it's spilling over 80 chars) - I tried using /x but it didn't work.
>
> I'd like something like the following (non working) code:
> if ($_ =~ /^(Number of events|
> nBytes|
> Total Real time|
> Total CPU time|
> Max Agent time)/x
> )
>
> Any ideas? Or is there a neater way to do this?
>
> --
> Martin DeMello
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4891
**************************************