[19154] in Perl-Users-Digest
Perl-Users Digest, Issue: 1349 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 21 18:05:34 2001
Date: Sat, 21 Jul 2001 15: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)
Message-Id: <995753110-v10-i1349@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 21 Jul 2001 Volume: 10 Number: 1349
Today's topics:
ANNOUNCE: SOAP::Lite v0.51 (Paul Kulchenko)
Re: Collin hates subject lines. <collin@crosslink.net>
Re: Collin hates subject lines. (Tad McClellan)
Re: Collin hates subject lines. <mbudash@sonic.net>
Re: Collin hates subject lines. (Eric Bohlman)
Re: Determing if a variable is a number? <gnarinn@hotmail.com>
Re: dumb question (Alexis Machin)
Re: dumb question <godzilla@stomp.stomp.tokyo>
Re: eval & quoting <stephh@nospam.com>
Re: eval & quoting nobull@mail.com
FAQ: I've read perlembed, perlguts, etc., but I can't e <faq@denver.pm.org>
Re: fetchall_arrayref (Kevin Reid)
Re: File Uploading nobull@mail.com
Re: File Uploading (David Efflandt)
Help with Berkeley_DB (Smedley)
Re: How to do this in perl? <abe@ztreet.demon.nl>
Re: How to do this in perl? <krahnj@acm.org>
regexp matching pairs (nobody)
Re: regexp matching pairs <james@zephyr.org.uk>
Re: regexp matching pairs <ilya@martynov.org>
Re: regexp matching pairs (Eric Bohlman)
Re: Repetitive if statements (Alexis Machin)
Re: Repetitive if statements <godzilla@stomp.stomp.tokyo>
Re: tab sperated line to named hash? (Eric Bohlman)
Tangled Up in Array <jc_va@spamisnotcool.hotmail.com>
Re: Tangled Up in Array nobull@mail.com
Re: Tangled Up in Array <bwalton@rochester.rr.com>
Re: Tangled Up in Array <jc_va@spamisnotcool.hotmail.com>
Re: Tangled Up in Array (Eric Bohlman)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Jul 2001 13:10:25 -0700
From: paulclinger@yahoo.com (Paul Kulchenko)
Subject: ANNOUNCE: SOAP::Lite v0.51
Message-Id: <tljobjo2kj188@corp.supernews.com>
It's my pleasure to announce that SOAP::Lite v0.51 has been released.
Change highlights since 0.50 (see Changes file for more information):
! fixed memory leak in SOAP::Parser (thanks to Ryan Adams and Michael
Brown)
! fixed skipping undef elements in arrays under Perl 5.005 (thanks to
Arne Georg Gleditsch)
! fixed POP3 server (thanks to Kevin Hutchinson)
! number of fixes in XMLRPC::Lite
fixed <string> requirement (thanks to Matthew Krenzer and Dana
Powers)
fixed empty slot skipping (thanks to Jon Udell)
fixed serialization of "0"/""/undef values (thanks to Michael E.
Gage)
fixed autodispatch (thanks to Craig Kelley)
+ added support for SOAP 1.2 (spec is still in draft, implementation
is subject to change)
+ added extended array support (only in deserializer)
+ modified XML::Parser::Lite to work on Perl 5.005 (thanks to John
Gotts)
+ modified deserializer to work with different schemas (1999/2001)
+ added JABBER transport
+ added MQ transport
+ added mod_xmlrpc transport (Apache::XMLRPC::Lite)
+ added TCP over SSL transport
+ added non-blocking TCP multiserver
+ included FastCGI transport (thanks to Marko Asplund
<marko.asplund@kronodoc.fi>)
+ added support for import directive in WSDL
+ added support for short (tModel) WSDL service descriptions
+ added support for multiple services/ports and allowed non-SOAP
bindings in WSDL
+ added full search example UDDI->WSDL->SOAP (fullsearch.pl)
+ added charset in response message for HTTP transport
+ modified dispatch for XMLRPC server to work exactly as for SOAP
server
+ added example with Inline::C module (inline.daemon).
Dispatch to C, C++, assembler, Java, Python and Tcl :).
+ all transport are available for both SOAP::Lite and XMLRPC::Lite:
HTTP (daemon, CGI, mod_perl), SMTP/POP3, TCP, IO, JABBER, MQ
+ tested on Perl 5.00503, 5.6.0, 5.6.1, 5.7.1 and 5.7.2
+ updated documentation and added new examples
Module is available from http://www.soaplite.com/,
and from CPAN (http://search.cpan.org/search?dist=SOAP-Lite).
Best wishes, Paul.
------------------------------
Date: Sat, 21 Jul 2001 09:33:33 -0400
From: "Collin E Borrlewyn" <collin@crosslink.net>
Subject: Re: Collin hates subject lines.
Message-Id: <3b598417$0$24415@dingus.crosslink.net>
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3B59342E.1944EAC4@acm.org...
> Collin E Borrlewyn wrote:
> >
> > I'm writing a signup script for part of a larger message board.
Everything
> > else works, but I've been having trouble with preferences. I've tracked
the
> > problem down to the following subroutine. (I don't know if the
indentation
> > will hold.)
> >
> > sub update_info(){
> ^^
> You're saying you don't want to accept any arguments so @_ will be empty
> (depending on how you call the sub.)
Forgive my ignorance, but I don't follow.
> sub update_info {
> my ( $id, $field, $value ) = @_;
Is there a good reason to do this? Apart from (perhaps) readability, I am
unaware of an advantage.
>
> use Fcntl ':flock'; # import LOCK_* constants
> open DATA,"< $userdir/$id" or return 0;
> flock DATA, LOCK_EX unless $^O =~ /Win/;
> my ( $data, @sig ) = <DATA>;
> close DATA;
>
> $data =~ s/$field\*(\S+)/$field*$value/;
That's very nice, but it wont work for my purposes. First, it wont let me
update the signature, which is stored with no label. Second, it doesn't let
people use spaces in their names. s/$field\*([^\t]+)/$field*$value/ would
fix the second but not the first problem.
I was more interested in why it wasn't working than how to make it work. I
can make it work by doing it differently, but the fact that this didn't work
when it should have is annoying me.
> open DATA, "> $userdir/$id" or return 0;
> flock DATA, LOCK_EX unless $^O =~ /Win/;
> print DATA $data, @sig;
> close DATA or return 0;
> return 1;
> }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
------------------------------
Date: Sat, 21 Jul 2001 09:42:08 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Collin hates subject lines.
Message-Id: <slrn9lj1lg.57m.tadmc@tadmc26.august.net>
Collin E Borrlewyn <collin@crosslink.net> wrote:
>"John W. Krahn" <krahnj@acm.org> wrote in message
>news:3B59342E.1944EAC4@acm.org...
>> Collin E Borrlewyn wrote:
>> > sub update_info(){
>> ^^
>> You're saying you don't want to accept any arguments so @_ will be empty
>> (depending on how you call the sub.)
>
>Forgive my ignorance, but I don't follow.
"Far More Than Everything You've Ever Wanted to Know about
Prototypes in Perl":
http://www.perl.com/pub/a/language/misc/fmproto.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 21 Jul 2001 15:51:42 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Collin hates subject lines.
Message-Id: <mbudash-C45A2C.08514221072001@news.sonic.net>
In article <3b58f78b$0$23492@dingus.crosslink.net>, "Collin E
Borrlewyn" <collin@crosslink.net> wrote:
> $data{$_[1]} = $data{$_[2]}; # Updates the element
i'm not sure about the other posters' comments about prototyping, but
based on your requirements, the above line should be:
$data{$_[1]} = $_[2]; # Updates the element
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: 21 Jul 2001 21:04:26 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Collin hates subject lines.
Message-Id: <9jcqoq$a0u$3@bob.news.rcn.net>
Collin E Borrlewyn <collin@crosslink.net> wrote:
> open(DATA,"$userdir/$_[0]") || return 0;
> flock(DATA,2) unless $^O =~ /Win/;
> my($data,@sig) = <DATA>;
> close(DATA);
> my @data = split(/\t/,$data);
> chomp($data);
[snip transformations]
> open(DATA,">$userdir/$_[0]") || return 0;
> flock(DATA,2) unless $^O =~ /Win/;
> print DATA $out."\n".$data{'SIG'};
> close(DATA) || return 0;
Nobody else in this thread has yet commented on the fact that your locking
is useless. In between the time you read the file and write it back, it's
unlocked and another process can grab it. You need to open the file for
read/write, lock it, read it, do your transformations, truncate the file,
write it and only *then* close it.
You should use constants imported from Fcntl rather than magic numbers.
flock() *is* implemented on Windows NT and 2000, just not on 95/98/ME.
Since multi-user programs are more likely to be run on the former than the
latter, you need a better test of flock()'s availabilty; see recent
threads for reliable ways to do it.
------------------------------
Date: Sat, 21 Jul 2001 16:00:53 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Determing if a variable is a number?
Message-Id: <995731253.911656884942204.gnarinn@hotmail.com>
In article <9jai3i$nrq$1@panix3.panix.com>, Stan Brown <stanb@panix.com> wrote:
>I'm writing a small PerlTK script to allow a user to edit some Oracle
>tables. The user will input data using PerlTK Entry widgets, and the script
>will then create the resultant SQL.
>
>Since numbers don't need to be quoted in SQL, and strings do, I need o
>figure out which of these variables are numbers.
>
if you use DBI and placeholders, you do not need to worry about quotes.
gnari
------------------------------
Date: Sat, 21 Jul 2001 19:36:38 GMT
From: a.m@myDesktop.somewhereOverTheRainbow.org.nospam (Alexis Machin)
Subject: Re: dumb question
Message-Id: <3b59d8cc.121441640@news.freeserve.co.uk>
On Fri, 20 Jul 2001 12:29:04 -0700, "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
[...]
>> You don't even understand what we are talking about, do you?
>
>Your use of plural "we" is confirmation of your flawed thinking and,
... blah blah blah...
<plonk>
During my time reading this group, the above poster's sole contribution appears to be
telling other posters they don't understand the question they're asking. Really, if
you've nothing constructive to add, why spend all that time posting garbage almost no
one will bother reading? Personally I fell asleep around 2 sentences in on this one.
I've learnt a lot reading the intelligent responses from most of the posters here,
BTW - just have to filter out the "Godzilla's" to up the s2n ratio a litte more...
--
Alexis Machin
------------------------------
Date: Sat, 21 Jul 2001 12:59:43 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: dumb question
Message-Id: <3B59DF2F.EA4046B2@stomp.stomp.tokyo>
Alexis Machin wrote:
> Godzilla! wrote:
> [...]
> >> You don't even understand what we are talking about, do you?
> >Your use of plural "we" is confirmation of your flawed thinking and,
> ... blah blah blah...
> <plonk>
> During my time reading this group, the above poster's sole contribution appears to be
> telling other posters they don't understand the question they're asking. Really, if
> you've nothing constructive to add, why spend all that time posting garbage almost no
> one will bother reading? Personally I fell asleep around 2 sentences in on this one.
> I've learnt a lot reading the intelligent responses from most of the posters here,
> BTW - just have to filter out the "Godzilla's" to up the s2n ratio a litte more...
pffffttt.... you are angry as a result of investing over a month's
worth of time and effort trying to trick me into posting files
over in the warez group with an intent of filing a formal complaint
hoping to have my account terminated.
However, this will truly crisp your cookies. Sure was easy enough
for me to con you into posting over a gigabyte of files, for naught.
Ain't I stinker? Sho nuff!
Godzilla! Queen Of Con.
------------------------------
Date: Sat, 21 Jul 2001 16:38:16 +0200
From: stephh <stephh@nospam.com>
Subject: Re: eval & quoting
Message-Id: <210720011638161557%stephh@nospam.com>
> $template = '<p><h1>$title</h1></p>Choose your choice:';
Use double quotes instead of simple.
This line should be:
$template = "<p><h1>$title</h1></p>Choose your choice:";
In article <9jbdqu$kulhd$1@ID-93885.news.dfncis.de>, Aman Patel
<patelnavin@icenet.net> wrote:
> I dont know but this code doesnt evaluate the contents of $template
>
>
> $fh = *STDOUT;
> $template = '<p><h1>$title</h1></p>Choose your choice:';
> eval {
> print $fh << X__END_OF_TEMPLATE_FILE__X;
> $template
> X__END_OF_TEMPLATE_FILE__X
> };
> ##check $@ of-course.
> ## The eval block should print the template variable (evaluated).
>
> But this prints:
> <p><h1>$title</h1></p>Choose your choice:
>
> The $title doesnt get replaced by the appropriate value.. If i removed the
> EVAL block than it comes out correct. I read the gory details about parsing
> quoted structures, but it didnt seem to help.
>
> I hope you guys have a explanation.
--
$tephh;
Don't forget to visit http://www.grc.com/dos/grcdos.htm
------------------------------
Date: 21 Jul 2001 17:58:13 +0100
From: nobull@mail.com
Subject: Re: eval & quoting
Message-Id: <u9g0bqdxsj.fsf@wcl-l.bham.ac.uk>
"Aman Patel" <patelnavin@icenet.net> writes:
> $fh = *STDOUT;
Change that to $fh=\*STDOUT
The fake GLOB variable type is a left-over from Perl4 and should be avoided.
> $template = '<p><h1>$title</h1></p>Choose your choice:';
> eval {
> print $fh << X__END_OF_TEMPLATE_FILE__X;
> $template
> X__END_OF_TEMPLATE_FILE__X
> };
> ##check $@ of-course.
> ## The eval block should print the template variable (evaluated).
No it should not. eval BLOCK simply traps exceptions - it does
nothing more. You are confusing eval BLOCK with eval EXPR.
> But this prints:
> <p><h1>$title</h1></p>Choose your choice:
No it does not, the space after the << generates an error.
> The $title doesnt get replaced by the appropriate value.. If i removed the
> EVAL block than it comes out correct.
Define "correct"
> I read the gory details about parsing
> quoted structures, but it didnt seem to help.
eval BLOCK is _not_ a quoted structure.
> I hope you guys have a explanation.
I think you meant:
$fh = \*STDOUT;
$template = '<p><h1>$title</h1></p>Choose your choice:';
eval qq{
print \$fh <<X__END_OF_TEMPLATE_FILE__X;
$template
X__END_OF_TEMPLATE_FILE__X
};
A little better IMHO is:
$fh = \*STDOUT;
$template = '<p><h1>$title</h1></p>Choose your choice:';
print $fh eval "<<X__END_OF_TEMPLATE_FILE__X\n$template\nX__END_OF_TEMPLATE_FILE__X\n";
Of course this sort of use of eval(EXPR) to implement templates means
that the templates can include arbitry Perl code (e.g. system('rm -rf
/')). If this a bad thing then consider the alternative given in the
FAQ.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 21 Jul 2001 18:17:04 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: I've read perlembed, perlguts, etc., but I can't embed perl in
Message-Id: <AGj67.4$T3.172044288@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
I've read perlembed, perlguts, etc., but I can't embed perl in
my C program; what am I doing wrong?
Download the ExtUtils::Embed kit from CPAN and run `make test'. If the
tests pass, read the pods again and again and again. If they fail, see
the perlbug manpage and send a bug report with the output of "make test
TEST_VERBOSE=1" along with "perl -V".
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
03.30
--
This space intentionally left blank
------------------------------
Date: Sat, 21 Jul 2001 20:59:07 GMT
From: kpreid@attglobal.net (Kevin Reid)
Subject: Re: fetchall_arrayref
Message-Id: <1ewwjz1.f3gnbnyvrwyeN%kpreid@attglobal.net>
cmavroudis <costas@othermedia.com> wrote:
> my $row;
> foreach $row ($goodrow)
> {
> $goodrow->{'status'};
> }
Should be:
foreach $row (@$goodrow)
{
$row->{'status'};
}
You might also want to consider:
* Using indenting.
* Doing something with the values.
* Combining the my with the foreach to limit $row's scope to the loop.
foreach my $row (@$goodrow) {
print $row->{'status'};
}
--
Kevin Reid: | Macintosh:
"I'm me." | Think different.
------------------------------
Date: 21 Jul 2001 18:22:31 +0100
From: nobull@mail.com
Subject: Re: File Uploading
Message-Id: <u9ae1ydwo8.fsf@wcl-l.bham.ac.uk>
"Blnukem" <blnukem@hotmail.com> writes:
> Hi All
Oh dear.
> I'm trying to upload files to my server and it works well except I cant
> seem to strip out the file path "c:\foo"
> I tried using $file =~ s/^.*(\\|\/)//; And that does the trick except the
> file size is 0 uploads nothing.
The thing returned by GCI::param() for an upload field is magically
both a file handle reference and a string containing the the file
name.
If you subject this value to s/// then is looses this magic and
becomes a normal string.
You must make a copy of the original value before modifying it and use
that copy as the filehandle.
Using strict and warnings would have helped you to trace this bug
yourself becasue you'd have got an error when you tried to use a
string as a filehandle. It is widely considered rude to come here and
ask for help without trying to help yourself first.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 21 Jul 2001 20:28:09 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: File Uploading
Message-Id: <slrn9ljpep.3lr.see-sig@typhoon.xnet.com>
On Sat, 21 Jul 2001 10:28:02 GMT, Blnukem <blnukem@hotmail.com> wrote:
> Hi All
> I'm trying to upload files to my server and it works well except I cant
> seem to strip out the file path "c:\foo"
> I tried using $file =~ s/^.*(\\|\/)//; And that does the trick except the
> file size is 0 uploads nothing. Here is a sample of my code:
>
> #!/usr/bin/perl
>
> $upload_path = '../files/';
>
> use CGI ':standard';
>
> print "Content-type: text/html\n\n";
>
> my $file = param ('uploadfile');
I have used the following which should work for Unix/Mac/Windows browsers
that include a path in the filename. Some systems are more difficult to
work with when there a spaces in filenames, so I convert those too. I
plugged this into your script here and it seems to work:
$file = $1 if $file =~ m|[/\\:]+([^/\\:]+)$|;
$file =~ s/\s/_/; # convert space to _
> if ($file) {
> open (UPLOAD, ">$upload_path/$file");
> my ($data, $length, $chunk);
>
> while ($chunk = read ($file, $data, 1024)) {
> print UPLOAD $data;
> $length += $chunk;
>
> }
> close (UPLOAD);
>
> print "<p>You uploaded <b>$file</b>.";
>
> }
>
>
>
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 21 Jul 2001 13:30:21 -0700
From: roadrunnerkrazykatovitch@hotmail.com (Smedley)
Subject: Help with Berkeley_DB
Message-Id: <25effc43.0107211230.7d237d1a@posting.google.com>
Hi,
I am trying to use DB_File.pm in a Linux environment within a CGI
script,
but I have gotten this message:
**************************************************
[Fri Jul 20 16:28:56 2001] DB_File.pm: [Fri Jul 20 16:28:56 2001]
DynaLoader.pm: DB_File object version 1.60 does not match $DB_File::
1.15
at /usr/lib/perl5/i386-linux/5.00404/DynaLoader.pm line 185. BEGIN
failed--compilation aborted at submitsquat.cgi line 5.
****************************************************
Can anyone tell me what this might mean? What should I ask the
sysadmin to do?
Also, I was trying to make DB_File.pm on my own personal Windows
machine, but I got this message :
BerkeleyDB.xs(52):Cannot open include file 'db.h': No such file or
directory.
I am making this build within the directory
C:\Berkeley_DB\perl.BerkeleyDB\ and I know that a copy of a file db.h
exists in the directory C:\Berkeley_DB\build_win32. Do I have to
explicitly edit the makefile to include this directory? The
documentation indicated that all variables would be immediately
generated.
Anyways, all responses would be appreciated.
Thanks,
Smedley
------------------------------
Date: Sat, 21 Jul 2001 18:10:07 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: How to do this in perl?
Message-Id: <db6jlt8qfj59jpt2793hqu055bh1igen5q@4ax.com>
On Fri, 13 Jul 2001 12:21:01 -0700, BCC <bcoon@sequenom.com> wrote:
> Hi,
>
> I have a system() call output that I need to parse...
>
> For example, in my script I have:
> $qstatout = system("/usr/pbs/bin/qstat -na");
>
> In this case, $qstatout is something like this:
No, it can't be, system() returns the exit status of the program you
called, _not_ it's output.
perldoc -f system
perldoc -f qx
perldoc perlop
...
> 5337.web1.defau nobody default 5053232920 -- 1 -- -- --
> Q --
> --
> 5339.web1.defau nobody default 5053232920 -- 1 -- -- --
> Q --
[ snip the rest of output example ]
> What I would like to do is write a sub that takes Jobname as an
> argument, get the 'S' column value corresponding to 'Jobname'. So if I
> want to find the 'S' (status) of Jobname 5053232920, I can call the sub,
> and return the status.
That 'Jobname' has two entries, which 'the status' would you like? Or
would you like a list with all of them?
> I was trying to match the position of 'S' in line 3, but then did not
> know how to begin the next match at that position. I read about using
> pos() and \g, but Im not sure thats what I need. Is this the best way
> to approach this?
I would pre process the output in a line-by-line way and stick all
relevant data in some data structure. Perhaps a hash of lists, with
'Jobname' as key and an array of stati as value.
It looks like the lines are formatted as fixed-width fields, so unpack()
could be useful to get the data you want off each line.
After reading your follow-up on line-wrapping,
here is one way it might look :
#!/usr/bin/perl -w
use strict;
my $ln_fmt = 'a15xa8xa8xa10xa6xa3xa3xa6xa4xaxa5';
# open a pipe to read from:
open STATS, '/usr/pbs/bin/qstat -na |' or die "Can't fork: $!";
# skip header (4 lines)
for ( 1..4 ) { my $skip = <STATS> }
# pre process data
my %status;
while ( <STATS> ) {
my( $jobname, $stat ) = ( unpack $ln_fmt, $_ )[3, 9];
push @{ $status{ $jobname } }, $stat;
# is there a non-data line between data lines?
my $skip = <STATS> unless eof STATS;
}
close STATS or die "Error in pipe: $! ($?)";
# use the data
my $job = '5053232920';
print "Status( $job ) = @{ $status{ $job } }\n";
__END__
--
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -we '$_="rekcah lreP rehtona tsuJ";print$2while s/(.*)(.)/$1/g'
------------------------------
Date: Sat, 21 Jul 2001 21:59:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to do this in perl?
Message-Id: <3B59FB57.FBB7C0C@acm.org>
Abe Timmerman wrote:
>
> After reading your follow-up on line-wrapping,
> here is one way it might look :
>
> #!/usr/bin/perl -w
> use strict;
>
> my $ln_fmt = 'a15xa8xa8xa10xa6xa3xa3xa6xa4xaxa5';
Any reason to keep the whitespace at the end of each field?
my $ln_fmt = 'A16A9A9A11A7A4A4A7A5A2A5';
> # open a pipe to read from:
> open STATS, '/usr/pbs/bin/qstat -na |' or die "Can't fork: $!";
>
> # skip header (4 lines)
> for ( 1..4 ) { my $skip = <STATS> }
>
> # pre process data
> my %status;
> while ( <STATS> ) {
>
> my( $jobname, $stat ) = ( unpack $ln_fmt, $_ )[3, 9];
> push @{ $status{ $jobname } }, $stat;
>
> # is there a non-data line between data lines?
> my $skip = <STATS> unless eof STATS;
> }
> close STATS or die "Error in pipe: $! ($?)";
>
> # use the data
> my $job = '5053232920';
> print "Status( $job ) = @{ $status{ $job } }\n";
>
> __END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 21 Jul 2001 20:46:23 GMT
From: nobody@nobody.com (nobody)
Subject: regexp matching pairs
Message-Id: <zSl67.93157$4m4.2374256@amsnews03.chello.com>
Hi All,
Here's my data:
my $data = q(
<tag>
testing
<tag>
testing2
</tag>
</tag>
<tag>
testing3
</tag>
);
Now I need a regext that will return the pairs in a list:
my @tags = $data =~ m{(<tag>.*?</tag>)}gs;
obviously this isn't going to work,
I want the tags list to hold:
@tags = ('
<tag>
testing
<tag>
testing2
</tag>
</tag>
','
<tag>
testing3
</tag>
');
so it's ok if it skips over embedded tags, but the pairs should be ok,
can anyone help with a good approach?
Y. Dobon
------------------------------
Date: Sat, 21 Jul 2001 21:58:19 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: regexp matching pairs
Message-Id: <MbkD7KhrzeW7Ewl2@gratiano.zephyr.org.uk>
In message <zSl67.93157$4m4.2374256@amsnews03.chello.com>, nobody
<nobody@nobody.com> writes
>so it's ok if it skips over embedded tags, but the pairs should be ok,
>can anyone help with a good approach?
Use the various HTML parsing modules on CPAN?
--
James Coupe PGP Key: 0x5D623D5D
"Surely somewhere out there there's a woman who's EBD690ECD7A1F
been sodomized by her father and is capable of B457CA213D7E6
composing a few coherent sentences on the subject." 68C3695D623D5D
------------------------------
Date: 22 Jul 2001 01:37:31 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: regexp matching pairs
Message-Id: <877kx2x8tg.fsf@abra.ru>
n> Here's my data:
n> my $data = q(
n> <tag>
n> testing
n> <tag>
n> testing2
n> </tag>
n> </tag>
n> <tag>
n> testing3
n> </tag>
n> );
n> Now I need a regext that will return the pairs in a list:
n> my @tags = $data =~ m{(<tag>.*?</tag>)}gs;
n> obviously this isn't going to work,
n> I want the tags list to hold:
n> @tags = ('
n> <tag>
n> testing
n> <tag>
n> testing2
n> </tag>
n> </tag>
n> ','
n> <tag>
n> testing3
n> </tag>
n> ');
n> so it's ok if it skips over embedded tags, but the pairs should be ok,
n> can anyone help with a good approach?
Unless you are using experimental syntax of Perl regexps it is
impossible to do it with single regexp (at least I think so). But you
can do it with following while loop:
my @tags = ();
my $level = 0;
while($data =~ m|\G(.*?)(</?tag>)|gs) {
my $chunk = $1;
my $tag = $2;
if($tag eq '<tag>') {
$level ++;
if($level == 1) {
push @tags, '';
$chunk = '';
}
}
if($level > 0) {
$tags[-1] .= $chunk;
$tags[-1] .= $tag;
}
if($tag eq '</tag>') {
$level --;
die 'Tag mismatch' if $level < 0;
}
}
die 'Tag mismatch' if $level > 0;
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 21 Jul 2001 21:45:28 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: regexp matching pairs
Message-Id: <9jct5o$let$2@bob.news.rcn.net>
nobody <nobody@nobody.com> wrote:
> Here's my data:
> my $data = q(
> <tag>
> testing
> <tag>
> testing2
> </tag>
> </tag>
> <tag>
> testing3
> </tag>
> );
> Now I need a regext that will return the pairs in a list:
Trying to do it with regexps is an exercise in masochism. I'd suggest
using Damian Conway's Text::Balanced module, which has a function for
extracting tagged text.
------------------------------
Date: Sat, 21 Jul 2001 19:50:13 GMT
From: a.m@myDesktop.somewhereOverTheRainbow.org.nospam (Alexis Machin)
Subject: Re: Repetitive if statements
Message-Id: <3b59dae5.121978687@news.freeserve.co.uk>
On Fri, 20 Jul 2001 20:39:26 -0700, "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
Man, I'm glad this one appeared before the filter kicked in on the next article
download...
> you will notice
>I deleted your image sizing. Rather than force a resize
>via html tags, resize your thumbnails with a graphics
>program such as photoshop or paint shop pro, to the
>actual size you want; 18 by 180 pixels.
>
>Your method of tag resizing graphics changes the visual
>size of your graphics but not the file size. A browser
>will still load the full size bytes and produce a scaled
>downed visual graphic. This really slows down a browser.
>Avoid this. Make "real" thumbnails and full size images
>as needed, with a clickable link to a full size. Your
>visitors will appreciate this although no word of thanks
>will come your way. Don't use tag resizing, it's not good.
Utter rubbish.
FYI, any professional developer will ensure the width and height properties are sent
down with an image. Although you've guessed correctly that sending down large images
then down sizing them on the page is not a good idea (not at all obvious, BTW), the
poster never demonstrated any intention of doing this. The reason we specify the
dimensions is to speed up the browser's rendering of a page; if it knows the size of
all images in advance, it can reserve the appropriate amount of space in the
document; and in browsers that dynamically reflow, it prevents the content from
jumping around as the images "pop" into place on the page, which doesn't look
particularly professional.
Of course, the layman may not be aware of this...
--
Alexis Machin
------------------------------
Date: Sat, 21 Jul 2001 13:26:04 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Repetitive if statements
Message-Id: <3B59E55C.8FBF77D3@stomp.stomp.tokyo>
Alexis Machin wrote:
> Godzilla! wrote:
(some snippage)
> Man, I'm glad this one appeared before the filter kicked in on the next article
> download...
You have killfiled me and I have tiny blue monkeys
flying out of my big butt, each harmoniously singing,
"Somewhere over the rainbow...."
> > you will notice
> >I deleted your image sizing. Rather than force a resize
> >via html tags, resize your thumbnails with a graphics
> >program such as photoshop or paint shop pro, to the
> >actual size you want; 18 by 180 pixels.
> >Your method of tag resizing graphics changes the visual
> >size of your graphics but not the file size. A browser
> >will still load the full size bytes and produce a scaled
> >downed visual graphic. This really slows down a browser.
> >Avoid this. Make "real" thumbnails and full size images
> >as needed, with a clickable link to a full size. Your
> >visitors will appreciate this although no word of thanks
> >will come your way. Don't use tag resizing, it's not good.
> Utter rubbish.
> Although you've guessed correctly that sending down large images
> then down sizing them on the page is not a good idea....
My oh my, will ya read yourself contradicting yourself in
the same breath! Goodness, you do seem to enjoy flaunting
your fatally flawed thinking!
> The reason we specify the....
There ya go again with that "we" stuff!! Have you lost
your personal identity by posing as so many fake people?
> Of course, the layman may not be aware of this...
I am most certain the originating author, which is you,
is aware he elected to select a posted methodology which
doesn't work, which is bad code and even said "thank you"
for this broken code.
Your fatally flawed thinking is rather humorous! However,
not as humorous as your missing nose which you cut off to
spite your face!
* laughs *
Godzilla! Queen Of Daddle Raspers.
------------------------------
Date: 21 Jul 2001 20:46:23 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: tab sperated line to named hash?
Message-Id: <9jcpmv$a0u$2@bob.news.rcn.net>
Tad McClellan <tadmc@augustmail.com> wrote:
> Twan Kogels <twanGEENSPAM@twansoft.com> wrote:
>>Now i have a lookup hash:
> [snip]
>>and a array:
>>this way i avoid 200 assignments.
> My way avoids 200 assignments too.
> I see no benefit of this approach compared to mine.
> What is objectionable about the hash slice method that I have shown?
The hash slice method still requires all the values in the array to be
copied into the hash, so it *is* doing 200 assignments, albeit in
heavily-optimized C code rather than with Perl operations. The lookup
method leaves the values in their original place and accesses them
indirectly, avoiding the need to copy them.
Of course, the relative time efficiency of the two is going to depend on
how frequenty the values are accessed and what proportion of them are
accessed on each iteration. If only a small proportion will be accessed
on any iteration, then the lookup method will probably win; if most or all
of them have to be accessed then the slice method will probably be better
because the overhead of the indirection (implemented with Perl operations)
will probably add up to more than the overhead of copying. Needless to
say, only a benchmark will answer for sure.
------------------------------
Date: Sat, 21 Jul 2001 16:29:45 GMT
From: "Buck Turgidson" <jc_va@spamisnotcool.hotmail.com>
Subject: Tangled Up in Array
Message-Id: <Z5i67.191956$Md.42471698@typhoon.southeast.rr.com>
I have a Perl program which I have been working on, with help from
this group. I made a performance enhancement, and it no longer works.
I am confused as to it's behavior. I read in some SQL column mappings
to change, and update a SQL file in one slurp. However, the mappings
are screwed up.
This is my input file:
ACCOUNT#_UK=ACCOUNT_NUM_UK
ACCOUNT#=ACCOUNT_NUM
ADDL#=ADDL_NBR
account#_uk=account_num_uk
account#=account_num
addl#=addl_nbr
Account#_Uk=Account_Num_Uk
Account#=Account_Num
Addl#=Addl_Nbr
However, the print statement in my Perl is only printing:
ACCOUNT#_UK <-> ACCOUNT_NUM_UK
ACCOUNT#
account#_uk <-> account_num_uk
account#
Account#_Uk <-> Account_Num_Uk
Account#
I cannot figure out why it doesn't essentially print the entire input
file, which is loaded into an array. I split the array on '='.
#!/usr/bin/perl -w
%readsuffixes = ("sql","yes");
$convertfile = 'c:\uf\work\convert.txt';
$sourcedirname = 'c:\uf\work\sqrin';
$outdirname = 'c:\uf\work\sqrout';
#--------------------------------------------------
#
#Load array with conversion pairs
#from conversion file. Load upper,lower, and proper
#case versions
#
#File format: EMPL_RCD#=EMPL_RCD
#
#--------------------------------------------------
$/='\n';
open(CONVERT, $convertfile) or die "Can't find $convertfile : $! \n";
while( $line = <CONVERT> ) {
$pairs = $line;
chomp($pairs);
push @convertpairs, uc($pairs);
push @convertpairs, lc($pairs);
$pairs = lc($pairs);
$pairs =~ s/([a-z]+)/\u$1/g;
push @convertpairs, $pairs;
}
#--------------------------------------------------
#
#Read input directory, apply all regexes in array
#to file. File is "slurped" in one gulp.
#
#--------------------------------------------------
undef $/;
opendir(DIR,$sourcedirname) or die "Can't open $sourcedirname: $! \n";
@files = readdir(DIR);
foreach $file (@files) {
if((-e "$sourcedirname$file") || (-e "$sourcedirname\\$file")) {
$file =~ /([^.]*)\.(\w*)/;
$suffix = lc($2);
if(exists($readsuffixes{$suffix})) {
print "$sourcedirname\\$file ";
$filename = "$sourcedirname\\$file";
open(INFILE,$filename) or die "Can't open $filename\n";;
$outfilename = ">$outdirname\\$file";
open(OUTFILE,$outfilename) or die "Can't open
$filename\n";;
print "$outfilename\n";
$fileswritten += 1;
$filecontents = <INFILE>;
foreach $arrayelement(@convertpairs) { #
@pair = split /=/, $arrayelement; #
print "$pair[0] <-> $pair[1]\n"; #
$filecontents =~ s/$pair[0]/$pair[1]/g; #
}
print OUTFILE $filecontents;
}
close(INFILE);
close(OUTFILE);
}
}
closedir(DIR);
print "\n Files written: $fileswritten\n";
------------------------------
Date: 21 Jul 2001 18:14:59 +0100
From: nobull@mail.com
Subject: Re: Tangled Up in Array
Message-Id: <u9d76udx0s.fsf@wcl-l.bham.ac.uk>
"Buck Turgidson" <jc_va@spamisnotcool.hotmail.com> writes:
> I have a Perl program which I have been working on, with help from
> this group. I made a performance enhancement, and it no longer works.
> I am confused as to it's behavior.
Get into "use strict" and declaring your variables in the smallest
scope sooner rather than later. I have no idea if your lack of
strictures contributes to your confusion on this occasion but unless
you like the thill of climbing without ropes then get into good habits
_now_. (Also thrill seekers who climb without ropes and are forever
needing to be rescued are considered a pain by others).
Your code contains the line:
> $/='\n';
This sets the input record separator to the character pair of a
backslash followed by the letter n.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 21 Jul 2001 18:18:48 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Tangled Up in Array
Message-Id: <3B59C78F.228ED1A@rochester.rr.com>
Buck Turgidson wrote:
>
> I have a Perl program which I have been working on, with help from
> this group. I made a performance enhancement, and it no longer works.
> I am confused as to it's behavior. I read in some SQL column mappings
> to change, and update a SQL file in one slurp. However, the mappings
> are screwed up.
>
> This is my input file:
>
> ACCOUNT#_UK=ACCOUNT_NUM_UK
> ACCOUNT#=ACCOUNT_NUM
> ADDL#=ADDL_NBR
> account#_uk=account_num_uk
> account#=account_num
> addl#=addl_nbr
> Account#_Uk=Account_Num_Uk
> Account#=Account_Num
> Addl#=Addl_Nbr
>
> However, the print statement in my Perl is only printing:
>
> ACCOUNT#_UK <-> ACCOUNT_NUM_UK
> ACCOUNT#
> account#_uk <-> account_num_uk
> account#
> Account#_Uk <-> Account_Num_Uk
> Account#
>
> I cannot figure out why it doesn't essentially print the entire input
> file, which is loaded into an array. I split the array on '='.
>
> #!/usr/bin/perl -w
> %readsuffixes = ("sql","yes");
>
...
> $/='\n';
> open(CONVERT, $convertfile) or die "Can't find $convertfile : $! \n";
> while( $line = <CONVERT> ) {
...
I think your main problem is in assigning $/ the value \n. Note: that
is not a newline, it is a two-character string consisting of one \ and
one n. Try
$/="\n";
and see how you make out. Also, it would help a lot if you could pare
your code down to just the subset that is giving trouble -- trying to
work around all the directories and data input files (which you don't
provide examples of anyway) just slows us down and makes it less likely
you will get a response.
--
Bob Walton
------------------------------
Date: Sat, 21 Jul 2001 18:18:50 GMT
From: "Buck Turgidson" <jc_va@spamisnotcool.hotmail.com>
Subject: Re: Tangled Up in Array
Message-Id: <eIj67.192367$Md.42608227@typhoon.southeast.rr.com>
This is a very unforgiving newsgroup. But...point well taken. Thanks
for your help. That was my problem.
<nobull@mail.com> wrote in message
news:u9d76udx0s.fsf@wcl-l.bham.ac.uk...
> "Buck Turgidson" <jc_va@spamisnotcool.hotmail.com> writes:
>
> > I have a Perl program which I have been working on, with help from
> > this group. I made a performance enhancement, and it no longer
works.
> > I am confused as to it's behavior.
>
> Get into "use strict" and declaring your variables in the smallest
> scope sooner rather than later. I have no idea if your lack of
> strictures contributes to your confusion on this occasion but unless
> you like the thill of climbing without ropes then get into good
habits
> _now_. (Also thrill seekers who climb without ropes and are forever
> needing to be rescued are considered a pain by others).
>
> Your code contains the line:
>
> > $/='\n';
>
> This sets the input record separator to the character pair of a
> backslash followed by the letter n.
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: 21 Jul 2001 21:37:56 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Tangled Up in Array
Message-Id: <9jcsnk$let$1@bob.news.rcn.net>
Buck Turgidson <jc_va@spamisnotcool.hotmail.com> wrote:
> This is a very unforgiving newsgroup. But...point well taken. Thanks
> for your help. That was my problem.
I don't think "unforgiving" is the right word. Rather, we have high
expectations of the people who come here. "Demanding" is probably a
better term. We expect posters to stretch themselves a bit, since that's
the only way people learn well. Spoon-feeding doesn't work, because the
learner never internalizes knowledge that way; at best he memorizes
magical incantations. Nor does presenting the learner with something way
over his head and expecting him to jump ten feet in the air; all that does
is make the learner feel incompetent. "No pain, no gain" is a stupid
philosophy, but "no *effort*, no gain" is the way the world works.
IMHO, about 80% of becoming a good programmer is simply learning to behave
like one. That means using all the resources available to you (like
warnings, strictures, tainting, the excellent free documentation that
comes with perl, etc.). It means looking things up, rather than guessing,
when you're not sure about something; there's absolutely *no* shame in
having to consult a reference. It means observing the coding habits of
other good programmers and, if you don't understand *why* they're doing
something, finding out why (it *doesn't* mean uncritically adopting
someone else's coding style). It means testing your code. It means
assuming that Mr. Murphy is going to visit your code very frequently, and
adopting measures to keep him from running wild.
All these factors are either attitudes or learned skills; they don't
involve any special talents not posessed by anyone intelligent enough to
use a computer. True, it probably takes some special talents to become a
*great* programmer on the order of Knuth or the like, but not every
programmer needs to be a great programmer, just a good one (and most truly
great programmers would be bored to death with most of the programming
work that needs to get done).
All the attudinal/behavioral factors can be summed up as "pride of
craftsmanship."
------------------------------
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 1349
***************************************