[25507] in Perl-Users-Digest
Perl-Users Digest, Issue: 7751 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 8 00:05:39 2005
Date: Mon, 7 Feb 2005 21:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 7 Feb 2005 Volume: 10 Number: 7751
Today's topics:
Re: 'Subroutine redefined' annoyance <please_post@nomail.edu>
Re: 'Subroutine redefined' annoyance <abigail@abigail.nl>
Re: 'Subroutine redefined' annoyance (Anno Siegel)
Re: [OT] Re: Perl - permute? <tadmc@augustmail.com>
Re: [OT] Re: Perl - permute? <flavell@ph.gla.ac.uk>
Re: [OT] Re: Perl - permute? <postmaster@castleamber.com>
Re: CGI - web content into variable <noreply@gunnar.cc>
Re: CGI - web content into variable <tadmc@augustmail.com>
Re: CGI - web content into variable <larry_wallet@yahoo.com>
Re: CGI - web content into variable <andy@aaelectron.co.uk>
Re: Custom sort empties instead of sorting <groleau+news@freeshell.org>
Re: nntp scan <tadmc@augustmail.com>
Re: one more IP addr regexp <tintin@invalid.invalid>
Re: should be simple..but eh Can you help <tadmc@augustmail.com>
Re: should be simple..but eh Can you help <tallstyk@yahoo.com>
Re: To compare dates in a script <noreply@gunnar.cc>
Trouble with Regexps <generic_x@hotmail.com>
Re: Trouble with Regexps <1usa@llenroc.ude.invalid>
Re: Trouble with Regexps <noreply@gunnar.cc>
Re: Trouble with Regexps <1usa@llenroc.ude.invalid>
Re: Trouble with Regexps <jeffrey.rossATairways.co.nz@no.spam>
Re: Trouble with Regexps <see.sig@rochester.rr.com>
Re: Trouble with Regexps ioneabu@yahoo.com
What constitutes a masterpiece? chris.raplee@gmail.com
Re: What constitutes a masterpiece? babydoe@mailinator.com
Re: What constitutes a masterpiece? Randal_Schwartzcopf@yahoo.com
Re: What constitutes a masterpiece? <postmaster@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 7 Feb 2005 23:53:32 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <cu8v1s$dcb$1@reader2.panix.com>
In <20050207164620.318$sS@newsreader.com> xhoster@gmail.com writes:
>bill <please_post@nomail.edu> wrote:
>> The problem seems to be that the 'use SlicesDices' statement is
>> causing the file to be read again. Is there any reasonably scalable
>> way to import the subs in @SlicesDices::EXPORT to the main namespace
>> without using "use", and not causing the redefinition to take place?
>Out of curiousity, what do mean by scalable in this context?
Bad wording on my part. I just wanted to rule out strategies
involving a bazillion assignments a la:
*quux = \&SlicesDices::quux;
*foo = \&SlicesDices::foo;
*bar = \&SlicesDices::bar;
...
*baz = \&SlicesDices::baz;
bill
------------------------------
Date: 08 Feb 2005 00:10:25 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <slrnd0g0rh.g2.abigail@alexandra.abigail.nl>
bill (please_post@nomail.edu) wrote on MMMMCLXXVIII September MCMXCIII in
<URL:news:cu8v1s$dcb$1@reader2.panix.com>:
!! In <20050207164620.318$sS@newsreader.com> xhoster@gmail.com writes:
!!
!! >bill <please_post@nomail.edu> wrote:
!!
!! >> The problem seems to be that the 'use SlicesDices' statement is
!! >> causing the file to be read again. Is there any reasonably scalable
!! >> way to import the subs in @SlicesDices::EXPORT to the main namespace
!! >> without using "use", and not causing the redefinition to take place?
!!
!! >Out of curiousity, what do mean by scalable in this context?
!!
!! Bad wording on my part. I just wanted to rule out strategies
!! involving a bazillion assignments a la:
!!
!! *quux = \&SlicesDices::quux;
!! *foo = \&SlicesDices::foo;
!! *bar = \&SlicesDices::bar;
!! ...
!! *baz = \&SlicesDices::baz;
You mean, something like (untested):
{ no strict 'refs';
*$_ = \&{"Slices::Dices::$_"}
for grep {/^[a-zA-Z]/} @SlicesDices::EXPORT;
}
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: 8 Feb 2005 00:48:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <cu929g$1oi$1@mamenchi.zrz.TU-Berlin.DE>
bill <please_post@nomail.edu> wrote in comp.lang.perl.misc:
> In <cu8kug$ljr$3@mamenchi.zrz.TU-Berlin.DE>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
[...]
> to it in a directory in my $PATH. In this way I can call the script
> from the command line, or "use" it from another script.
>
> If there's a better way that meet all my neurotic criteria, I'd
> love to hear it.
A module doing double-time as a script? Besides the obvious shebang line,
check caller() to see if you want to execute the "script code" (untested):
if ( caller ) {
OddsAndEnds->import(); # parameters as needed
require Getopt::STD; # for instance
# more script code here
}
package OddsAndEnds;
BEGIN {
our @ISA = qw( Exporter);
# other initialization of module
}
# etc...
The script part will only execute when it is called from the command
line, not if use'd or require'd (see perldoc -f caller). If so, it
will jump through your module's import hoops. Stuff that only the
script needs should be require'd, not use'd. Since imports in the
script happen at run time, you'll have to use parens with imported
functions, but that's the only restriction I see.
If you want the script first and the module later (I prefer it that way)
you'll have to put module initialization code in a BEGIN block as
indicated.
Anno
------------------------------
Date: Mon, 7 Feb 2005 17:04:57 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: [OT] Re: Perl - permute?
Message-Id: <slrnd0ft0p.rqp.tadmc@magna.augustmail.com>
John Bokma <postmaster@castleamber.com> wrote:
> Usenet is not a forum.
Yes it is.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 7 Feb 2005 23:24:55 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: [OT] Re: Perl - permute?
Message-Id: <Pine.LNX.4.61.0502072321250.21395@ppepc56.ph.gla.ac.uk>
On Mon, 7 Feb 2005, Tad McClellan reveals that:
> John Bokma <postmaster@castleamber.com> wrote:
>
> > Usenet is not a forum.
Now I wonder why I never saw that posting, until you followed-up to
it. (I should follow your own good example, and keep a copy of the
incidents which produce killfile entries ;-)
> Yes it is.
For those who choose to join in, right.
------------------------------
Date: 7 Feb 2005 23:48:12 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: [OT] Re: Perl - permute?
Message-Id: <Xns95F6B51A7C74castleamber@130.133.1.4>
Alan J. Flavell wrote:
> incidents which produce killfile entries ;-)
Only lamers brag about their killfiles.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Tue, 08 Feb 2005 00:21:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI - web content into variable
Message-Id: <36qbm2F55pcrjU1@individual.net>
Andrew Armstrong wrote:
> (The documentation at
> http://search.cpan.org/~gaas/libwww-perl-5.803/lib/LWP/Simple.pm on
> the other hand is almost but not quite understandable enough at my
> present knowledge level.)
What is it in the LWP::Simple docs you don't understand?
use LWP::Simple;
my $content = get($url);
works fine for me.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 7 Feb 2005 17:23:42 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: CGI - web content into variable
Message-Id: <slrnd0fu3u.rt7.tadmc@magna.augustmail.com>
Andrew Armstrong <asa@aaelectron.co.uk> wrote:
> Subject: CGI - web content into variable
There is nothing about CGI in your question you know...
> I am new to PERL,
It is spelled "Perl".
> and finding the documentation difficult to understand.
>
> What I want to do is to retrieve information from a web page.
Have you seen the Perl FAQ about fetching web pages?
How do I fetch an HTML file?
> I can view the
> page in a browser, but what I want to do is get the content into a variable
> so I can get the item of information for further use.
use LWP::Simple;
my $html = get 'http://www.perl.org';
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Feb 2005 16:58:31 -0800
From: "Larry" <larry_wallet@yahoo.com>
Subject: Re: CGI - web content into variable
Message-Id: <1107824311.044610.305210@z14g2000cwz.googlegroups.com>
Andrew Armstrong wrote:
>
> Probably the main problem I face is that the documentationI have
found assumes
> more knowledge than it is easy to get as a beginner when most of the
> documentation makes little sense. The text book I have that I
understand un
> fortunately doesn't go far enough for all the things I have to make
work.
>
> Andrew
In the study of software engineering, I recommend that you start from
the beginning.
In C, that would be:
#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}
in Perl,
print 'Hello, World!';
Once you have a solid understanding of these basic concepts, take it
one step at a time. For several thousand US dollars, you can have a
famous Perl book author come to your home and tutor you.
------------------------------
Date: Tue, 08 Feb 2005 01:16:38 +0000
From: Andrew Armstrong <andy@aaelectron.co.uk>
Subject: Re: CGI - web content into variable
Message-Id: <0f4g01dv62iulfcc35jti6ojpfg7mir699@4ax.com>
On Tue, 08 Feb 2005 00:21:47 +0100, Gunnar Hjalmarsson <noreply@gunnar.cc>
wrote:
>Andrew Armstrong wrote:
>> (The documentation at
>> http://search.cpan.org/~gaas/libwww-perl-5.803/lib/LWP/Simple.pm on
>> the other hand is almost but not quite understandable enough at my
>> present knowledge level.)
>
>What is it in the LWP::Simple docs you don't understand?
>
> use LWP::Simple;
> my $content = get($url);
>
>works fine for me.
Yes, that did seem understandable, though it didn't work at first. What was not
clear to me from the documentation was the precise usage of the more complex
LWP::UserAgent; form.
However, both now work after I added
print "Content-type: text/html\n\n";
in each case
Thank you for showing me this code. I might be able to write something vaguely
comparable in the future now I have seen this - but otherwise it would have
probably take a week of trial, error, error, and error.
Andrew
------------------------------
Date: Mon, 07 Feb 2005 23:43:25 -0500
From: Wes Groleau <groleau+news@freeshell.org>
Subject: Re: Custom sort empties instead of sorting
Message-Id: <36qub0F52vmvtU1@individual.net>
Anno Siegel wrote:
>>1. I said the array after sorting is EMPTY.
>
> Okay, it shouldn't be empty, but you only mentioned "empty" in the
> subject.
Sorry. But I did say it came from a hash.
> No. A hash key can *never* be undefined, it is always a string. Also,
Hmm. I didn't know that. I thought there was a slim chance
that some error during creation of the hash might have used
an undef for a key.
> you didn't say that 5 was supposed to be the last element in the array.
> There could have been any number of undef's beyond that.
No, not the last, just one of the three cells I tested.
I believe there were over two thousand entries at the
time I tested. I can see that a sort (especially when
order is important for only two items) would be most
inefficient. But whatever my attempted sort did was
so fast that there was no noticeable delay between
invocation and error message.
Since my code worked for you, I wonder whether there
is a peculiar bug in my installation.
I may do some testing for that if I ever can afford them
time. But the grep solution works fine anyway.
--
Wes Groleau
"Lewis's case for the existence of God is fallacious."
"You mean like circular reasoning?"
"He believes in God. Therefore, he's fallacious."
------------------------------
Date: Mon, 7 Feb 2005 17:09:10 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: nntp scan
Message-Id: <slrnd0ft8m.rqp.tadmc@magna.augustmail.com>
ruud <geen@mail.invalid> wrote:
> Sherm Pendley wrote:
>
>>> HASH(0xa145268)
>>>
>>> As you can see, no names.
>>> What am i doing wrong here ?
>>
>> The very first line of the documentation for the posters() method
>> that it returns a hash reference. As the output shows, that's what you
>> got. Why do you think something's wrong?
>
> Hmm, i was expecting real human readeble names.
Then you either did not read, or did not understand, the documentation
for the function that you are using.
A hashref is not "human readable".
If you de-reference the reference you are likely to find that
it contains such names.
> Back to the drawingboard :-)
No, back to the documentation for the module that you are using,
followed by the documentation that reveals how to dereference references.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 8 Feb 2005 13:57:50 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: one more IP addr regexp
Message-Id: <36qh12F54km9dU1@individual.net>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:36q3p8F563a3bU1@individual.net...
> Tintin wrote:
>> Vasily Pomuran wrote:
>>>
>>>/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/
>>
>> Would be useful if it matched valid IP addresses.
>>
>> 1.1.1.1.1 is not a valid IP address.
>
> It doesn't match that either.
>
> my $re =
> qr/\b((\d|1{0,1}\d{2}|2[01234]\d|25[012345])\.){3}(\d|1{0,1}\d{2}|2[01234]\d|25[012345])\b/;
> my $ip = '1.1.1.1.1';
> print "$1\n" if $ip =~ /($re)/;
>
> Outputs:
> 1.1.1.1
Depends on how you use the regex.
If you say match, you are generally doing:
if (/some regex/) {
print "matched\n";
}
else {
print "not matched\n";
}
Anyway, I like using
http://search.cpan.org/~adamk/Validate-Net-0.5/lib/Validate/Net.pm
for validating IP addresses.
------------------------------
Date: Mon, 7 Feb 2005 17:11:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: should be simple..but eh Can you help
Message-Id: <slrnd0ftck.rqp.tadmc@magna.augustmail.com>
Bob <tallstyk@yahoo.com> wrote:
> Subject: should be simple..but eh Can you help
Please put the subject of your article in the Subject of your article.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Feb 2005 13:30:14 -0800
From: "Bob" <tallstyk@yahoo.com>
Subject: Re: should be simple..but eh Can you help
Message-Id: <1107811814.946144.148630@l41g2000cwc.googlegroups.com>
Ok thanks to all of you. You are awesome and I am really taking a
liking to this language..
I opted for the solution to set my input seperator to "\n\n" and it
works like a charm!
------------------------------
Date: Tue, 08 Feb 2005 00:07:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: To compare dates in a script
Message-Id: <36qareF576u8vU1@individual.net>
clearguy02@yahoo.com wrote:
> I have a file that has two entrees (a name and a date) seperated by a
> tab. I need to get only all those names in the file if the date on the
> each line is greater than a certain date, 12-31-2004.
>
> Script
> #######################
> $current = "31-Dec-04";
> foreach (<DATA>) {
> ($f, $l) = /(\w+)\t+(\w+)/;
> print $f if ($l > $current);
> }
> __DATA__
> 5.5.25.50 01-Feb-05
> TEST1 22-Jul-04
> BSTOP 03-Sep-02
> DB00004639 21-Jan-05
> DB00004693 25-Jan-05
> CDM_3.1.0 27-May-03
> ############################
>
> I think I am failing on comparing stuff.
Obviously.
warning: Argument "31Dec04" isn't numeric in numeric gt
You need to make things comparable in order to compare them...
> How can I rectify the above code?
You can:
1) enable strictures
2) enable warnings
3) declare the variables you are using
4) use an appropriate module - I would suggest Date::Parse
5) refrain from unnecessarily loading the whole file into memory
6) study "perldoc perlre" to find out that \w does not match
what you think it matches
use strict;
use warnings;
use Date::Parse;
my $current = str2time('31-Dec-04');
while (<DATA>) {
my ($f, $l) = /(.+)\t(.+)/;
print "$f\n" if str2time($l) > $current;
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 7 Feb 2005 16:45:40 -0800
From: "evlika" <generic_x@hotmail.com>
Subject: Trouble with Regexps
Message-Id: <1107823540.705549.197640@l41g2000cwc.googlegroups.com>
Hi all,
Can't seem to find the right way to extract what I need
Here is what I have:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
DISAG]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Here is what I need:
ASCP ASCP [PACK 1,(2,3) FLO DISAG] 21-50-04-00
AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
The columns are seperated by spaces not tabs. The second example I have
no
problem with. The first one has data on a second line that should be on
the
first line/appended to the second column. Any thoughts?
Thanks!
------------------------------
Date: Tue, 08 Feb 2005 01:58:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Trouble with Regexps
Message-Id: <Xns95F6D560EB3B3asu1cornelledu@127.0.0.1>
"evlika" <generic_x@hotmail.com> wrote in news:1107823540.705549.197640
@l41g2000cwc.googlegroups.com:
> Hi all,
> Can't seem to find the right way to extract what I need
>
> Here is what I have:
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
> DISAG]
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
>
> Here is what I need:
>
> ASCP ASCP [PACK 1,(2,3) FLO DISAG] 21-50-04-00
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
This is one of those cases where the lowly substr comes in handy. I have
a feeling someone will post something infinitely neater, but if the
column widths are always the same, then you can do something along the
lines of:
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @parsed;
{
local $/ =
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\n";
while(my $line = <DATA>) {
chomp $line;
my @segments = split "\n", $line;
next unless @segments;
my $segment = shift @segments;
my $left = substr $segment, 0, 26;
my $mid = substr $segment, 27, 30;
my $right = substr $segment, 58;
$left =~ s/\s+$//g;
$right =~ s/^\s+//g;
$mid =~ s/^\s+//g;
$mid =~ s/\s+$//g;
for my $s (@segments) {
$s =~ s/^\s+//g;
$s =~ s/\s+$//g;
$mid .= $s;
}
push @parsed, {
field1 => $left,
field2 => $mid,
field3 => $right,
};
}
}
print Dumper \@parsed;
__DATA__
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
DISAG]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
D:\Home\asu1\UseNet\clpmisc> b
$VAR1 = [
{
'field1' => 'ASCP',
'field2' => 'ASCP [PACK 1,(2,3) FLODISAG]',
'field3' => '1-50-04-00'
},
{
'field1' => 'AUTO DISABLE RL',
'field2' => 'AUTO DISABLE RL',
'field3' => '1-31-04-00'
}
];
------------------------------
Date: Tue, 08 Feb 2005 02:54:48 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Trouble with Regexps
Message-Id: <36qkp1F51gtmlU1@individual.net>
evlika wrote:
>
> Here is what I have:
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
> DISAG]
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
> Here is what I need:
>
> ASCP ASCP [PACK 1,(2,3) FLO DISAG] 21-50-04-00
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
>
> The columns are seperated by spaces not tabs. The second example I
> have no problem with. The first one has data on a second line that
> should be on the first line/appended to the second column. Any
> thoughts?
Maybe something along these lines:
my @rec;
my $i = -1;
while (<>) {
if( substr($_, 0, 1) eq '@' ) {
map { s/\s*$// } @{ $rec[$i] } if $rec[$i];
$i++;
next;
}
no warnings qw(substr uninitialized);
$rec[$i][0] .= substr($_, 0, 27);
$rec[$i][1] .= substr($_, 27, 22);
$rec[$i][2] .= substr($_, 57, 11);
}
print join("\n", @$_), "\n\n" for @rec;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 08 Feb 2005 02:00:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Trouble with Regexps
Message-Id: <Xns95F6D5BA2AB9Fasu1cornelledu@127.0.0.1>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns95F6D560EB3B3asu1cornelledu@127.0.0.1:
> my $right = substr $segment, 58;
Despite my assertions, it seems like I really don't know how to count.
That should be:
my $right = substr $segment, 57;
Sinan
------------------------------
Date: Tue, 8 Feb 2005 15:11:55 +1300
From: "Jeffrey Ross" <jeffrey.rossATairways.co.nz@no.spam>
Subject: Re: Trouble with Regexps
Message-Id: <42081ae7$1@news.iconz.co.nz>
"evlika" <generic_x@hotmail.com> wrote in message
news:1107823540.705549.197640@l41g2000cwc.googlegroups.com...
> Hi all,
> Can't seem to find the right way to extract what I need
>
> Here is what I have:
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
> DISAG]
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
>
> Here is what I need:
>
> ASCP ASCP [PACK 1,(2,3) FLO DISAG] 21-50-04-00
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
>
>
> The columns are seperated by spaces not tabs. The second example I have
> no
> problem with. The first one has data on a second line that should be on
> the
> first line/appended to the second column. Any thoughts?
>
> Thanks!
>
Assuming that your data is in a file called infile and that the 'columns'
are always separated by at least 2 consecutive spaces, that 2 consecutive
space are not present within a 'column', that the optional continuation line
starts with a space, and that "@" in column 1 indicates a separation line,
awk -F" *" '
$0 ~ /^@/ {print f1, f2, f3; f1=f2=f3=""; next}
f1 == "" {f1=$1; f2=$2; f3=$3; next}
{f2=f2 " " $0; next}
END {print f1, f2, f3}
' <infile
In English this may be interpreted as... use awk with two or more spaces as
field separators.
If a line starts with "@" print f1, f2, and f3. Clear f1, f2, and f3. Skip
to next line.
If f1 is empty store field1 in f1, field2 in f2, and field3 in f3. Skip to
next line.
Append this line (which better be the continuation line!) to f2. Skip to
next line.
Once the last line has been processed, print f1, f2, and f3 (in case there's
no final separator line).
The data is read from infile.
Note that I have not tested this, so it may not bequite right but should
give you a a start. It will print a blank line at the beginning and maybe
another at the end. You can avoid that by using "if (f1 != "") print ...".
If the assumptions above do not match your data this solution probably won't
work.
It's probably cleaner in Perl, but I'm more of an awk expert. It would be
much better if you could generate your data with clearer column divisions.
Regards,
Jeffrey.
------------------------------
Date: Tue, 08 Feb 2005 02:35:56 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Trouble with Regexps
Message-Id: <gAVNd.28085$8H2.7619@twister.nyroc.rr.com>
evlika wrote:
> Hi all,
> Can't seem to find the right way to extract what I need
>
> Here is what I have:
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
> DISAG]
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
>
> Here is what I need:
>
> ASCP ASCP [PACK 1,(2,3) FLO DISAG] 21-50-04-00
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
>
>
> The columns are seperated by spaces not tabs. The second example I have
> no
> problem with. The first one has data on a second line that should be on
> the
> first line/appended to the second column. Any thoughts?
Well, the actual format of your incoming data is not apparent, so
any responses will have be based upon assumptions. For example,
with my assumptions indicated in []:
Is the "second field" the only one that can be continued onto the
next line, or can the "first field" and "third field" also be
continued sometimes? [the first and seconds fields may be
continued, the third may not, since there is no way to specify a
third continuation field unless there is a non-empty second field
continuation unless the fields are column-based]
Are "records" always separated with a line containing nothing but
a bunch of @'s? [yes]
Can there be two, three, or more continuation lines, or is it
limited to just one? [indefinite number]
Are the input "fields" delimited by two or more space characters,
or do they occur within specific "columns"? [two or more space
characters, implies a field cannot contain two or more
consecutive space characters]
Is there always a @-line at the start of the data? At the end of
the data? [yes, always @-line at beginning and end]
When continuations are appended, is a space character inserted? [yes]
Given those assumptions:
use strict;
use warnings;
my @fields;
while(<DATA>){
chomp;
if(/^\@+$/){
#remove unwanted extra spaces
for my $f(@fields){
$f=~s/^ +//;
$f=~s/ +$//;
$f=~s/ +/ /g;
}
print "$fields[0] $fields[1] $fields[2]\n"
if @fields;
@fields=();
next;
}
else{
my @pf=$_=~/(.*?)(?: ?$| {2,}(.*?)(?: ?$| {2,}(.*)))/;
die "Input error" unless @pf;
no warnings 'uninitialized';
for my $i(0..2){
$fields[$i].=' '.$pf[$i];
}
}
}
__END__
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
DISAG]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
generates the output you say you want (with some liberty taken to
prevent wrapping of your data lines -- I shortened them a bit).
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 7 Feb 2005 20:11:28 -0800
From: ioneabu@yahoo.com
Subject: Re: Trouble with Regexps
Message-Id: <1107835888.336961.91370@z14g2000cwz.googlegroups.com>
evlika wrote:
> Hi all,
> Can't seem to find the right way to extract what I need
>
> Here is what I have:
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> ASCP ASCP [PACK 1,(2,3) FLO 21-50-04-00
> DISAG]
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
>
> Here is what I need:
>
> ASCP ASCP [PACK 1,(2,3) FLO DISAG] 21-50-04-00
> AUTO DISABLE RL AUTO DISABLE RL 21-31-04-00
>
>
> The columns are seperated by spaces not tabs. The second example I
have
> no
> problem with. The first one has data on a second line that should be
on
> the
> first line/appended to the second column. Any thoughts?
>
> Thanks!
#!/usr/bin/perl
use strict;
use warnings;
my $arrayref = [ ];
my @record;
while (<>)
{
if ($_ !~ /^@+$/)
{
@record = /(.+)\s{2,}(.+)\s{2,}(.+)/;
}
push @$arrayref, [ @record ];
}
for (@$arrayref)
{
print "$_->[0]\t$_->[1]\t$_->[2]\n" if scalar @$_ == 3;
}
------------------------------
Date: 7 Feb 2005 18:02:29 -0800
From: chris.raplee@gmail.com
Subject: What constitutes a masterpiece?
Message-Id: <1107828149.384741.11570@g14g2000cwa.googlegroups.com>
masterpiece(noun)
1 : a work done with extraordinary skill; especially : a supreme
intellectual or artistic achievement
2 : a piece of work presented to a medieval guild as evidence of
qualification for the rank of master
What constitutes a masterpiece in Perl?
------------------------------
Date: 7 Feb 2005 19:33:59 -0800
From: babydoe@mailinator.com
Subject: Re: What constitutes a masterpiece?
Message-Id: <1107833639.737927.241660@c13g2000cwb.googlegroups.com>
chris.raplee@gmail.com writes:
> What constitutes a masterpiece in Perl?
Try exercises Chapter~16 of Learning Perl (3rd ed).
That was the most satisfying hour I've spent since
I hit puberty.
------------------------------
Date: 7 Feb 2005 19:37:28 -0800
From: Randal_Schwartzcopf@yahoo.com
Subject: Re: What constitutes a masterpiece?
Message-Id: <1107833848.185829.209150@l41g2000cwc.googlegroups.com>
chris.raplee@gmail.com wrote:
> masterpiece(noun)
> 1 : a work done with extraordinary skill; especially : a supreme
> intellectual or artistic achievement
> 2 : a piece of work presented to a medieval guild as evidence of
> qualification for the rank of master
>
>
> What constitutes a masterpiece in Perl?
#!/usr/bin/perl
use Net::NNTP;
my $nntp = Net::NNTP->new("news.server");
my $groups = $nntp->list();
for (keys %$groups)
{
print "group: $_\n";
$nntp->group($_);
my %spam;
my %extra_spam;
while (my $a = $nntp->head())
{
for (@$a)
{
if (/^from:/i)
{
/<(.*)>/;
$spam{$1}++ if $1;
$extra_spam{$1}++ if $1 =~ /NOSPAM/;
print $1, "\n" if $1;
}
}
$nntp->next();
}
}
$nntp->quit;
------------------------------
Date: 8 Feb 2005 04:36:05 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: What constitutes a masterpiece?
Message-Id: <Xns95F6E5EA2B75Fcastleamber@130.133.1.4>
wrote:
> masterpiece(noun)
> 1 : a work done with extraordinary skill; especially : a supreme
> intellectual or artistic achievement
> 2 : a piece of work presented to a medieval guild as evidence of
> qualification for the rank of master
>
> What constitutes a masterpiece in Perl?
Putting something at CPAN and have it mentioned here at least once a month
as something that helps to make a task easier.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7751
***************************************