[13659] in Perl-Users-Digest
Perl-Users Digest, Issue: 1069 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 15 15:12:08 1999
Date: Fri, 15 Oct 1999 12:11:55 -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: <940014714-v9-i1069@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Oct 1999 Volume: 9 Number: 1069
Today's topics:
multiple SUB's reading from single Filehandle? yeah@rite.net
Re: multiple SUB's reading from single Filehandle? <jeffp@crusoe.net>
Re: multiple SUB's reading from single Filehandle? <gellyfish@gellyfish.com>
Re: multiple SUB's reading from single Filehandle? <aqumsieh@matrox.com>
Need a hand-Databases, Hahses, and Odd Photos. <garmark2NOgaSPAM@hotmail.com.invalid>
Re: Need a hand-Databases, Hahses, and Odd Photos. <bwalton@rochester.rr.com>
Need help getting all searched info to display... rwswebmaster@my-deja.com
Re: Need help getting all searched info to display... <jtribbeck@argogroup.com>
Re: Need help getting all searched info to display... (Larry Rosler)
Re: Need help getting all searched info to display... <jtribbeck@argogroup.com>
Re: Need help getting all searched info to display... <ltl@rgsun5.viasystems.com>
Need help getting data into arrays <srhagan@holta.lucent.com>
Re: Need help getting data into arrays <webmaster@webdream.com>
Re: Need help getting data into arrays <uri@sysarch.com>
Re: Need help getting data into arrays (Craig Berry)
Re: Need help getting data into arrays <gellyfish@gellyfish.com>
Re: Need help getting data into arrays <neale.morison@fujitsu.com.au>
Re: Need help getting data into arrays <neale.morison@fujitsu.com.au>
Re: Need help getting data into arrays <neale.morison@fujitsu.com.au>
Need script to do reverse lookups on list of IPs (Dean Carpenter)
Re: Need script to do reverse lookups on list of IPs <rootbeer@redcat.com>
Re: Need script to do reverse lookups on list of IPs <makkulka@cisco.com>
Re: Need script to do reverse lookups on list of IPs (Dean Carpenter)
Needs Perl bindings done for new Corba environment battery841@usa.net
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Oct 1999 13:07:00 -0400
From: yeah@rite.net
Subject: multiple SUB's reading from single Filehandle?
Message-Id: <2bkEOO0wFH0JdP7aQaf7iXiPOFGb@4ax.com>
Hi there,
Ive been fighting with some perl code recently, im attempting to do
(basically) the following:
openit();
do_one();
do_two();
do_three();
sub openit {
open(FH,"netstat -nr|");
}
sub do_one {
while(<FH>) {
print $_;
}
sub do_two {
while(<FH>) {
print $_;
}
sub do_three {
while(<FH>) {
print $_;
}
whats seems to be happening is after the first sub routine FH seems to
be empty'd, is there a faq on this kind of filehandle manipulation?
Any hints or pointers are greatly appreciated!
wherbert1@earthlink.net (drop the 1)
------------------------------
Date: Wed, 13 Oct 1999 13:25:35 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: multiple SUB's reading from single Filehandle?
Message-Id: <Pine.GSO.4.10.9910131322540.14462-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 13, yeah@rite.net blah blah blah:
> openit();
> do_one();
> do_two();
> do_three();
>
> sub openit {
> open(FH,"netstat -nr|");
> }
> sub do_one {
> while(<FH>) {
> print $_;
> }
> sub do_two {
> while(<FH>) {
> print $_;
> }
> sub do_three {
> while(<FH>) {
> print $_;
> }
>
> whats seems to be happening is after the first sub routine FH seems to
> be empty'd, is there a faq on this kind of filehandle manipulation?
Um, yeah, that's what it does. You basically say:
while (there is content from this filehandle){
print it
}
You do that three times. The second and third time, there's no content.
What "kind of filehandle manipulation" are you trying to do?
--
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN
------------------------------
Date: 13 Oct 1999 20:59:01 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: multiple SUB's reading from single Filehandle?
Message-Id: <7u2rql$ck$1@gellyfish.btinternet.com>
On Wed, 13 Oct 1999 13:07:00 -0400 yeah@rite.net wrote:
> Hi there,
> Ive been fighting with some perl code recently, im attempting to do
> (basically) the following:
>
> openit();
> do_one();
> do_two();
> do_three();
>
> sub openit {
> open(FH,"netstat -nr|");
> }
> sub do_one {
> while(<FH>) {
> print $_;
> }
> sub do_two {
> while(<FH>) {
> print $_;
> }
> sub do_three {
> while(<FH>) {
> print $_;
> }
>
> whats seems to be happening is after the first sub routine FH seems to
> be empty'd, is there a faq on this kind of filehandle manipulation?
perldoc -f seek
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Fri, 15 Oct 1999 10:35:59 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: multiple SUB's reading from single Filehandle?
Message-Id: <x3y7lko7kts.fsf@tigre.matrox.com>
yeah@rite.net writes:
> whats seems to be happening is after the first sub routine FH seems to
> be empty'd, is there a faq on this kind of filehandle manipulation?
Of course. There is a FAQ for almost all of your questions. From
perlfaq9:
=head2 How can I make a filehandle local to a subroutine?
How do I pass filehandles between subroutines?
How do I make an array of filehandles?
> Any hints or pointers are greatly appreciated!
Ok. Try perldoc. Type 'perldoc perldoc' at your shell for more
info. The '-q' option, available for recent Perl's only, is quite
helpful.
HTH,
--Ala
------------------------------
Date: Thu, 14 Oct 1999 18:28:38 +1700
From: garmark <garmark2NOgaSPAM@hotmail.com.invalid>
Subject: Need a hand-Databases, Hahses, and Odd Photos.
Message-Id: <11f733ec.cfbca5cb@usw-ex0102-011.remarq.com>
Hello,
I am workingon a database script for a photos archive from concerts
for a site, and it is drivin by a database.
database is like this:
005::20thshow::some other irrelevant stuff.
The first line is the filename of the photo minus the extension for
thumbnailing porposes, and the second line is the show/concert from
which the photo was taken.
I want to be able to print in tables:
20thshow
*005
but seeing as how a zillion lines in he database will have the same
second field i want to be able to sort them. Some wonderful chap sent
me some code, but I'm too stupid to get it to work.
so let me know what is wrong with the subroutine at the bottom ok?
thanks ver much! I reall appriciate it. I know i am missing something
very integral, but i can't figure it out.
If you offer some assistance i will give ou some crdit on the site iam
working on.
anway thanks again:
blaine garrett
sub view {
&HTMLHead;
print "<CENTER><P><IMG SRC=\"/images/layout/title_photos.gif\"
HEIGHT=35 WIDTH=270><BR>\n";
print "random thumbnails go here, probably a subroutine<BR>\n";
print "<B>View Photos by Show/Event</B><BR>\n";
#new stuff with hashes.
open (DATA, "$datapath") || &ErrorOut;
@data = <DATA>;
close (DATA);
my @shows;
my %show_listed;
my %photosl;
my($shows,$shows) = split "::";
if( !$shows_listed{$shows} ) {
push @shows, $shows;
$show_listed{$shows}=1;
}
push @{$photos{$shows}}, $photos; }
for my $shows( @shows ) {
print "$shows\n";
for my $photos ( @{$photos{$show}} ) {
print " $photos\n";
}
}
#
&HTMLFoot;
exit;
}
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Thu, 14 Oct 1999 22:18:46 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Need a hand-Databases, Hahses, and Odd Photos.
Message-Id: <38068F06.9A49C003@rochester.rr.com>
garmark wrote:
>
> Hello,
> I am workingon a database script for a photos archive from concerts
> for a site, and it is drivin by a database.
> database is like this:
> 005::20thshow::some other irrelevant stuff.
> The first line is the filename of the photo minus the extension for
> thumbnailing porposes, and the second line is the show/concert from
> which the photo was taken.
> I want to be able to print in tables:
>
> 20thshow
> *005
>
> but seeing as how a zillion lines in he database will have the same
> second field i want to be able to sort them. Some wonderful chap sent
> me some code, but I'm too stupid to get it to work.
> so let me know what is wrong with the subroutine at the bottom ok?
> thanks ver much! I reall appriciate it. I know i am missing something
> very integral, but i can't figure it out.
...
> blaine garrett
>
> sub view {
> &HTMLHead;
> print "<CENTER><P><IMG SRC=\"/images/layout/title_photos.gif\"
> HEIGHT=35 WIDTH=270><BR>\n";
> print "random thumbnails go here, probably a subroutine<BR>\n";
> print "<B>View Photos by Show/Event</B><BR>\n";
> #new stuff with hashes.
> open (DATA, "$datapath") || &ErrorOut;
> @data = <DATA>;
You never use @data in this sub. (???!) You probably mean something
more along the lines of (especially if you actually have
"a zillion" lines of data):
while(<DATA>){
$data=$_;
> close (DATA);
and then delay the close until after the end of the while loop.
>
> my @shows;
> my %show_listed;
> my %photosl;
If you put in a while loop, these initializations should be moved
to before the start of the loop.
> my($shows,$shows) = split "::";
What are you splitting here? $_ was never given a value in this sub
(plus this use of $_ is deprecated). And what are you splitting it
to? You have the same variable listed twice. If you intended to
split a data record like those you show above, it should be
something like:
my($shownumber,$showname,$rest)=split /::/,$data,3;
where $data is the variable holding the string you want to split.
>
> if( !$shows_listed{$shows} ) {
-
You call this hash $show_listed everywhere else in this sub.
> push @shows, $shows;
> $show_listed{$shows}=1;
> }
>
> push @{$photos{$shows}}, $photos; }
In the above, the hash $photos was never given any value in this
sub. Also, you are using the very dangerous technique of using a
data value as the name of a Perl variable (an array in this case).
Consider what would happen if $photos{$shows} just happened to have
the value "shows", for example. Use a hash to store your arrays,
rather than putting them directly into Perl's namespace.
> for my $shows( @shows ) {
> print "$shows\n";
> for my $photos ( @{$photos{$show}} ) {
> print " $photos\n";
> }
> }
> #
> &HTMLFoot;
> exit;
> }
>
...
Your routine needs a lot more work than just fixing the above-mentioned
items.
--
Bob Walton
------------------------------
Date: Thu, 14 Oct 1999 14:14:29 GMT
From: rwswebmaster@my-deja.com
Subject: Need help getting all searched info to display...
Message-Id: <7u4ofm$kug$1@nnrp1.deja.com>
I am looking at this file:
TLH S NGM MOS GUIDANCE 10/14/99 0000 UTC
DAY /OCT 14 /OCT 15 /OCT 16
HOUR 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12
MX/MN 90 63 85 66
TEMP 69 66 65 79 87 88 76 69 67 66 66 76 82 83 74 71 70 68 67
DEWPT 69 66 64 65 61 60 62 61 60 60 61 64 63 62 63 63 64 63 63
CLDS SC SC SC SC SC SC SC CL CL CL SC SC SC SC SC SC CL SC SC
WDIR 00 00 00 03 03 03 01 03 04 03 03 04 05 04 02 03 03 03 03
WSPD 00 00 00 07 08 08 02 02 03 04 05 10 11 11 05 07 06 07 07
POP06 4 0 0 3 1 6 17 14 18
POP12 0 4 16 23
QPF 0/ 0/ 0/0 0/ 0/0 0/ 0/0 0/ 0/0
TSV06 28/ 0 15/ 0 8/ 0 8/ 0 6/ 1 13/ 0 11/ 0 16/ 1 14/ 0
TSV12 26/ 0 9/ 0 14/ 1 17/ 0
PTYPE R R R R R R R R R R R R R R R
POZP 0 0 0 0 0 1 0 0 2 1 0 0 2 0 0
POSN 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
SNOW 0/ 0/ 0/0 0/ 0/0 0/ 0/0 0/ 0/0
CIG 7 7 7 7 7 7 7 7 7 7 7 7 7
VIS 5 4 4 5 5 5 5 5 5 5 4 5 5
OBVIS F F F N N N N N N F F N N
Now, I just want to capture the part between "TLH" and "OBVIS",
separated by new lines. My code is:
open(FILE, "NGMMOS.txt");
undef $/;
my $names ="";
my @names = ();
$f = <FILE>;
while ($f =~/TLH(.*?)OBVIS/s) {
$names = $1;
$f= $';
@names = split (/\n+/ , $names);
last;
$a=0;
foreach $el (@names) {
$a++;
}
}
close(FILE);
$/="\n";
The problem is, this is all that is shown:
S NGM MOS GUIDANCE 10/14/99 0000 UTC
DAY /OCT 14 /OCT 15 /OCT 16
HOUR 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12
MX/MN 90 63 85 66
TEMP 69 66 65 79 87 88 76 69 67 66 66 76 82 83 74 71 70 68 67
DEWPT 69 66 64 65 61 60 62 61 60 60 61 64 63 62 63 63 64 63 63
CLDS SC SC SC SC SC SC SC CL CL CL SC SC SC SC SC SC CL SC SC
WDIR 00 00 00 03 03 03 01 03 04 03 03 04 05 04 02 03 03 03 03
WSPD 00 00 00 07 08 08 02 02 03 04 05 10 11 11 05 07 06 07 07
POP06 4 0 0 3 1 6 17 14 18
POP12 0 4 16 23
QPF 0/ 0/ 0/0 0/ 0/0 0/ 0/0 0/ 0/0
TSV06 28/ 0 15/ 0 8/ 0 8/ 0 6/ 1 13/ 0 11/ 0 16/ 1 14/
I am unsure why it stops searching where it does and where the rest of
the string should be. It anybody can figure out why it is doing this,
a response would be greatly appreciated.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 14 Oct 1999 18:29:58 +0100
From: Jason P Tribbeck <jtribbeck@argogroup.com>
Subject: Re: Need help getting all searched info to display...
Message-Id: <38061316.FE92771F@argogroup.com>
rwswebmaster@my-deja.com wrote:
>
> I am looking at this file:
<snip>
> The problem is, this is all that is shown:
<snip>
Errm - actually, nothing is shown!
I'm not entirely sure why you're using a while loop to do what you want
to do, unless the file has more than one entry - and then you'd want
while($f=~/TML(.*?)OBVIS/gs)
or something.
Ahh - I belive that's probably what you want to do.
In that case, use:
while($f=~/TML(.*?)OBVIS/gs) {
$names=$1
@names=split(/\n+/ , $names);
...
}
Note that you don't need $f=$' anymore, which would slow down /all/
regexes in your program.
This script will automatically stop at the first record anyway, as you
have
last;
in there.
Also, if the purpose of $a is to count the number of elements in @names,
then you can easily do
$a=$#names;
Why it's stopping at TSV12, I don't know - under my Unix system, $names
becomes the required list. It may be that you're running under NT, and
the CRLF has been messed up...
--
Jason Tribbeck Argo Interactive
ltd
Senior Design Engineer 7 Dukes Court,
Chichester
West Sussex, PO19
2FX
Tel: +44 1243 815 815 Fax: +44 1243 815 805
England
------------------------------
Date: Thu, 14 Oct 1999 10:56:40 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Need help getting all searched info to display...
Message-Id: <MPG.126fb934900a101f98a094@nntp.hpl.hp.com>
In article <38061316.FE92771F@argogroup.com> on Thu, 14 Oct 1999
18:29:58 +0100, Jason P Tribbeck <jtribbeck@argogroup.com> says...
...
> Also, if the purpose of $a is to count the number of elements in @names,
> then you can easily do
>
> $a=$#names;
Err, no, unless someone has played obscene games with $[.
$a = @names;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 15 Oct 1999 10:40:12 +0100
From: Jason P Tribbeck <jtribbeck@argogroup.com>
Subject: Re: Need help getting all searched info to display...
Message-Id: <3806F67C.B869BAE3@argogroup.com>
Larry Rosler wrote:
>
> In article <38061316.FE92771F@argogroup.com> on Thu, 14 Oct 1999
> 18:29:58 +0100, Jason P Tribbeck <jtribbeck@argogroup.com> says...
>
> ...
>
> > Also, if the purpose of $a is to count the number of elements in @names,
> > then you can easily do
> >
> > $a=$#names;
>
> Err, no, unless someone has played obscene games with $[.
>
> $a = @names;
I've had problems with that in the past - and I tend to avoid it.
Having said that, I've also had no problems with that in the past too,
so I tend to avoid it, and use $#array which I've had no problems with.
I can't exactly remember where it worked and where it didn't work, but
it isn't anything to do with $[.
--
Jason Tribbeck Argo Interactive
ltd
Senior Design Engineer 7 Dukes Court,
Chichester
West Sussex, PO19
2FX
Tel: +44 1243 815 815 Fax: +44 1243 815 805
England
------------------------------
Date: 15 Oct 1999 15:30:48 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: Need help getting all searched info to display...
Message-Id: <7u7hb8$kfu$1@rguxd.viasystems.com>
Jason P Tribbeck <jtribbeck@argogroup.com> wrote:
:>Larry Rosler wrote:
:>> Err, no, unless someone has played obscene games with $[.
:>>
:>> $a = @names;
:>I've had problems with that in the past - and I tend to avoid it.
But you should still recognize the difference in the numbers that
go into $a. One is the count and the other is the index of the
last entry. Two different numbers.
:>Having said that, I've also had no problems with that in the past too,
:>so I tend to avoid it, and use $#array which I've had no problems with.
If it makes you feel better, that's fine for now. When you get
more comfortable with the gestalt, you'll know when to use each
where it is most appropriate. But use ($#array + 1) if you want the
count and are going to avoid @names in scalar context to get that
count for you.
:>I can't exactly remember where it worked and where it didn't work, but
:>it isn't anything to do with $[.
It's all about context. See discussions of scalar vs. list context
in the documentation.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Thu, 14 Oct 1999 13:32:27 -0400
From: srhagan <srhagan@holta.lucent.com>
Subject: Need help getting data into arrays
Message-Id: <380613AB.2092A934@holta.lucent.com>
Hi Everyone,
I'm *really* inexperienced when it comes to doing anything with arrays
other than simple hashes and scalars. I don't even understand how to use
a reference. So keep that in mind when reading this.
Here's the big picture of what I'm trying to do. The input to my
program is an email message that is piped in as STDIN. The format of the
input is all of the mail headers, followed by several long lines of
data. Each line of data starts with the text "Date submitted", so I'm
using that to identify the lines I want.
Each of the lines that I want to use is formatted like this ( I
truncated the lines for brevity -- they're actually about 5 times this
length).
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:01|pec14_Qty:|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_zip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
What I need to do is get each of these lines (and I never know how many
there will be), into a hash table.
So, I need to:
1. Read in data
2. Select lines that begin with "Date submitted"
3. Transform each line into a hash table.
My first idea was to read the data as STDIN into an array:
@data=<STDIN>
Then loop through and assign each acceptable line to a new variable,
then split each variable into a scalar array, and then convert each
scalar array into a hash. My first problem can in trying to assign each
line to a new variable so I would end up with:
$submission_1 = ('Date submitted:Tue Oct 12 15:18:53 EDT 1999',
'pec29_Qty:123', 'ae_hrid:1234598')
$submission_2 = ('Date submitted:Tue Oct 12 15:18:53 EDT 1999',
'pec29_Qty:123', 'ae_hrid:1234598')
etc...
I tried this:
$i=0;
foreach $item (@data){
if ((substr $item, 0, 15) eq "Date submitted:"){
$submission_$i=split (/|/, $item);
$i++
}
That was actually my last problem because, as you probably guessed, the
$submission$i didn't work and I couldn't figure out how to get assign a
new, sequential name to each item.
After that's worked out, I need to know if there is a way to turn a list
like this:
$submission_1 = ('Date submitted:Tue Oct 12 15:18:53 EDT 1999',
'pec29_Qty:123', 'ae_hrid:1234598')
into a hash:
%submission_1=("Date submitted"=>"Tue Oct 12 15:18:53 EDT 1999",
"pec29_Qty"=>"123",
"ae_hrid"=>"1234598")
(I realize that I have to do something with the "Data Submitted" field
because of the colons in the date format.)
So, can anyone help?
Please copy me via email to srhagan@lucent.com
Thanks,
Susan Hagan
------------------------------
Date: Thu, 14 Oct 1999 18:31:19 GMT
From: "Craig Vincent" <webmaster@webdream.com>
Subject: Re: Need help getting data into arrays
Message-Id: <XjpN3.531$CQ.385@198.235.216.4>
@foo = split(/|/, <STDIN>);
Theoretically that should break up each part and place it in a separate cell
each in the list.
I never tried doing a split directly with <STDIN>, if it doesn't work
perhaps first declare
a variable with <STDIN> as the value and then split that into a list.
Sincerely,
Craig Vincent
>
> @data=<STDIN>
>
> Then loop through and assign each acceptable line to a new variable,
> then split each variable into a scalar array, and then convert each
> scalar array into a hash. My first problem can in trying to assign each
> line to a new variable so I would end up with:
>
> $submission_1 = ('Date submitted:Tue Oct 12 15:18:53 EDT 1999',
> 'pec29_Qty:123', 'ae_hrid:1234598')
>
> $submission_2 = ('Date submitted:Tue Oct 12 15:18:53 EDT 1999',
> 'pec29_Qty:123', 'ae_hrid:1234598')
>
> etc...
>
> I tried this:
>
> $i=0;
> foreach $item (@data){
> if ((substr $item, 0, 15) eq "Date submitted:"){
> $submission_$i=split (/|/, $item);
> $i++
> }
>
> That was actually my last problem because, as you probably guessed, the
> $submission$i didn't work and I couldn't figure out how to get assign a
> new, sequential name to each item.
>
> After that's worked out, I need to know if there is a way to turn a list
> like this:
>
> $submission_1 = ('Date submitted:Tue Oct 12 15:18:53 EDT 1999',
> 'pec29_Qty:123', 'ae_hrid:1234598')
>
> into a hash:
>
> %submission_1=("Date submitted"=>"Tue Oct 12 15:18:53 EDT 1999",
>
> "pec29_Qty"=>"123",
>
> "ae_hrid"=>"1234598")
>
> (I realize that I have to do something with the "Data Submitted" field
> because of the colons in the date format.)
>
> So, can anyone help?
>
> Please copy me via email to srhagan@lucent.com
>
> Thanks,
>
> Susan Hagan
>
>
------------------------------
Date: 14 Oct 1999 15:23:31 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Need help getting data into arrays
Message-Id: <x7hfjtkaq4.fsf@home.sysarch.com>
>>>>> "CV" == Craig Vincent <webmaster@webdream.com> writes:
CV> @foo = split(/|/, <STDIN>);
please don't post untested code. you just posted a very common trap that
newbies fall into regarding regexes. | is a regex metachar and has to be
escaped to be a regular char to split upon.
CV> Theoretically that should break up each part and place it in a
CV> separate cell each in the list. I never tried doing a split
CV> directly with <STDIN>, if it doesn't work perhaps first declare a
CV> variable with <STDIN> as the value and then split that into a
CV> list.
and why wouldn't it work with <STDIN>? any reason to spread that doubt?
why didn't you try it? it takes only 1 line of code:
perl -e 'print join( ":", split /\|/, <STDIN>)'
dke|djje|jfjf|jwj
dke:djje:jfjf:jwj
was that so hard?
<snip of massive jeopardy quote>
and why quote the entire message when you only addressed one part (and
that incorrectly)? learn how to quote properly. it ia good netiquette.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 14 Oct 1999 20:33:07 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Need help getting data into arrays
Message-Id: <s0cfg3i4hu271@corp.supernews.com>
Craig Vincent (webmaster@webdream.com) wrote:
: @foo = split(/|/, <STDIN>);
:
: Theoretically that should break up each part and place it in a separate cell
: each in the list.
If your theory operates in some language other than Perl, perhaps.
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "They do not preach that their God will rouse them
a little before the nuts work loose." - Kipling
------------------------------
Date: 14 Oct 1999 21:30:09 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Need help getting data into arrays
Message-Id: <7u5i11$1g2$1@gellyfish.btinternet.com>
On Thu, 14 Oct 1999 18:31:19 GMT Craig Vincent wrote:
> @foo = split(/|/, <STDIN>);
>
> Theoretically that should break up each part and place it in a separate cell
> each in the list.
Yes that will break one line up into ever so teensy weensy parts of a
single character - please read the perlfunc entry for split about the
nature of the first argument to split and most probably perlre too .
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Fri, 15 Oct 1999 14:17:32 +1000
From: "Neale Morison" <neale.morison@fujitsu.com.au>
Subject: Re: Need help getting data into arrays
Message-Id: <7u69ng$tn5@newshost.fujitsu.com.au>
srhagan wrote in message <380613AB.2092A934@holta.lucent.com>...
>
>Hi Everyone,
>
>I'm *really* inexperienced when it comes to doing anything with arrays
>other than simple hashes and scalars. I don't even understand how to use
>a reference. So keep that in mind when reading this.
I think the following does what you want. I'm sure there are many on this ng
who could do it in two lines, and Abigail could do it all using only numeric
characters, cartoon swearing and q.
use strict;
my @field_refs = (); # array for storing references to field hashes
while (<DATA>) { # loop through DATA stream placing each line in $_
chomp; # remove newline on end of $_ string
if (/^Date submitted:/){ # check $_ for 'Date submitted' at beginning
my @fields = split /\|/; # split lines into fields on literal |
my %fieldhash=();
foreach my $field (@fields){
my ($key, $value) = split /:/, $field; # guess
$fieldhash{$key}=$value;
}
push @field_refs, \%fieldhash; # add fieldhash reference to array
}
}
foreach my $fieldhashref (@field_refs){ # get the values out again and see
if it worked
foreach my $key (sort keys %$fieldhashref) {
print "$key: $fieldhashref->{$key}\n";
}
print "\n\n";
}
__END__
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:01|pec14_Qty:|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_z
ip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
koala
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:02|pec14_Qty:|pec
39_Qty:55|pec1:45|pec24_Qty:9|cust_state:NSW|il_name:|pec2:|pec34_Qty:|cust_
zip:2040|pec3:|nac:99999|pec4:|dealer_state:VIC|
wombat
Date submitted:Wed Oct 13 15:18:53 EDT
1999|pec29_Qty:45|ae_hrid:987654|install_day:03|pec14_Qty:2|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_z
ip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
------------------------------
Date: Fri, 15 Oct 1999 14:47:41 +1000
From: "Neale Morison" <neale.morison@fujitsu.com.au>
Subject: Re: Need help getting data into arrays
Message-Id: <7u6bhq$une@newshost.fujitsu.com.au>
# This version works a little better.
# It strips leading and trailing key whitespaces
# to avoid undefined value errors
# when data has spaces at beginning or end
# You'll have to edit the test data lines to remove any newlines added by
newsreaders
use strict;
my @field_refs = (); # array for storing references to field hashes
while (<DATA>) { # loop through DATA stream placing each line in $_
chomp; # remove newline on end of $_ string
if (/^Date submitted:/){ # check $_ for 'Date submitted' at beginning
my @fields = split /\|/; # split lines into fields on literal |
my %fieldhash=();
foreach my $field (@fields){
my ($key, $value) = split /:/, $field; # guess
for ($key){
s/^\s*//; # remove whitespace at beginning
s/\s*$//; # remove whitespace at end
}
if ($key){
$fieldhash{$key}=$value;
}
}
push @field_refs, \%fieldhash; # add fieldhash ref to array
}
}
foreach my $fieldhashref (@field_refs){ # get the values out again
foreach my $key (sort keys %$fieldhashref) { # list all keys and values
print "$key: $fieldhashref->{$key}\n";
}
if ($fieldhashref->{'install_day'} > 1){ # refer to a particular key
print "WARNING: Install day is greater than 1!\n";
}
print "\n\n";
}
__END__
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:01|pec14_Qty:|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_z
ip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
koala
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:02|pec14_Qty:|pec
39_Qty:55|pec1:45|pec24_Qty:9|cust_state:NSW|il_name:|pec2:|pec34_Qty:|cust_
zip:2040|pec3:|nac:99999|pec4:|dealer_state:VIC|
wombat
Date submitted:Wed Oct 13 15:18:53 EDT
1999|pec29_Qty:45|ae_hrid:987654|install_day:03|pec14_Qty:2|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_z
ip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
------------------------------
Date: Fri, 15 Oct 1999 15:16:04 +1000
From: "Neale Morison" <neale.morison@fujitsu.com.au>
Subject: Re: Need help getting data into arrays
Message-Id: <7u6d58$v76@newshost.fujitsu.com.au>
# final version deals with separator colons in time value
# in Date submitted field
# better to find another expression for field/value separators
use strict;
my @field_refs = (); # array for storing references to field hashes
while (<DATA>) { # loop through DATA stream placing each line in $_
chomp; # remove newline on end of $_ string
if (/^Date submitted:/){ # check $_ for 'Date submitted' at beginning
my @fields = split /\|/; # split lines into fields on literal |
my %fieldhash=();
foreach my $field (@fields){
my ($key, $value);
if ($field =~ /^Date submitted:/){ # hack separator : in time
$key='Date submitted';
($value = $field) =~ s/^Date submitted://;
} else {
($key, $value) = split /:/, $field;
}
for ($key){
s/^\s*//; # remove whitespace at beginning
s/\s*$//; # remove whitespace at end
}
if ($key){
$fieldhash{$key}=$value;
}
}
push @field_refs, \%fieldhash; # add fieldhash ref to array
}
}
foreach my $fieldhashref (@field_refs){ # get the values out again
foreach my $key (sort keys %$fieldhashref) { # list all keys and values
print "$key: $fieldhashref->{$key}\n";
}
if ($fieldhashref->{'install_day'} > 1){ # refer to a particular key
print "WARNING: Install day is greater than 1!\n";
}
print "\n\n";
}
__END__
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:01|pec14_Qty:|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_z
ip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
koala
Date submitted:Tue Oct 12 15:18:53 EDT
1999|pec29_Qty:|ae_hrid:1234598|install_day:02|pec14_Qty:|pec
39_Qty:55|pec1:45|pec24_Qty:9|cust_state:NSW|il_name:|pec2:|pec34_Qty:|cust_
zip:2040|pec3:|nac:99999|pec4:|dealer_state:VIC|
wombat
Date submitted:Wed Oct 13 15:18:53 EDT
1999|pec29_Qty:45|ae_hrid:987654|install_day:03|pec14_Qty:2|pec
39_Qty:|pec1:12345|pec24_Qty:|cust_state:AK|il_name:|pec2:|pec34_Qty:|cust_z
ip:12345|pec3:|nac:12345|pec4:|dealer_state:AK|
------------------------------
Date: 13 Oct 1999 21:15:10 GMT
From: dean.carpenter@pharma.nospam.com (Dean Carpenter)
Subject: Need script to do reverse lookups on list of IPs
Message-Id: <8E5EAF82Ddeancarpenterpharmac@10.211.21.13>
Anyone have a pre-written script for this ?
I have a file of many thousands of IP addresses from a firewall logfile. I
need to run a (hopefully a multi-parallel) script to produce another file of
IP to dns-name matches.
--
Dean Carpenter deano@areyes.spam.com Remove the spam :)
94 TT :) Dean.Carpenter@pharma.spam.com to reply.
------------------------------
Date: Wed, 13 Oct 1999 15:28:09 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Need script to do reverse lookups on list of IPs
Message-Id: <Pine.GSO.4.10.9910131527550.25558-100000@user2.teleport.com>
On 13 Oct 1999, Dean Carpenter wrote:
> Subject: Need script to do reverse lookups on list of IPs
>
> Anyone have a pre-written script for this ?
If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 13 Oct 1999 15:52:13 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Need script to do reverse lookups on list of IPs
Message-Id: <38050D1D.9DCD4D01@cisco.com>
[Dean Carpenter wrote:
> Anyone have a pre-written script for this ?
> I have a file of many thousands of IP addresses from a firewall logfile. I
> need to run a (hopefully a multi-parallel) script to produce another file of
> IP to dns-name matches.]
Get Net::DNS from CPAN
Also I came across a script by name "mresolv2" for fast DNS lookups. See if
it works for you. This script is from Mike Ruhr's Home page.
http://www.fuhr.org/users/mfuhr/index.html
Also see.
http://www.fuhr.org/users/mfuhr/perldns/
http://www.fuhr.org/users/mfuhr/perldns/mresolv2
Hope this helps.
--
------------------------------
Date: 14 Oct 1999 15:03:02 GMT
From: dean.carpenter@pharma.nospam.com (Dean Carpenter)
Subject: Re: Need script to do reverse lookups on list of IPs
Message-Id: <8E5F706AFdeancarpenterpharmac@10.211.21.13>
makkulka@cisco.com (Makarand Kulkarni) wrote in
<38050D1D.9DCD4D01@cisco.com>:
>[Dean Carpenter wrote:
>
>> Anyone have a pre-written script for this ?
>> I have a file of many thousands of IP addresses from a firewall
>> logfile. I need to run a (hopefully a multi-parallel) script to
>> produce another file of IP to dns-name matches.]
>
>Get Net::DNS from CPAN
>
>Also I came across a script by name "mresolv2" for fast DNS lookups.
>See if it works for you. This script is from Mike Ruhr's Home page.
>http://www.fuhr.org/users/mfuhr/index.html
>
>Also see.
>http://www.fuhr.org/users/mfuhr/perldns/
>http://www.fuhr.org/users/mfuhr/perldns/mresolv2
Woo hoo. mresolv was *exactly* what I was looking for. The net rules.
--
Dean Carpenter deano@areyes.spam.com Remove the spam :)
94 TT :) Dean.Carpenter@pharma.spam.com to reply.
------------------------------
Date: Wed, 13 Oct 1999 02:05:07 GMT
From: battery841@usa.net
Subject: Needs Perl bindings done for new Corba environment
Message-Id: <7u0pcc$ppn$1@nnrp1.deja.com>
Hey,
One of my friends, Bob, is working on a new Corba environment called
BLADE. BLADE is a Corba based web page development environment. He
needs someone to do Perl bindings for BLADE. If you're interested,
e-mail Bob at bob@thestuff.net
Thanks
Kevin
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 1069
**************************************