[20003] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2198 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 25 00:05:50 2001

Date: Sat, 24 Nov 2001 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006664707-v10-i2198@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 24 Nov 2001     Volume: 10 Number: 2198

Today's topics:
        A Perl Bug? <jake@chaogic.com>
        can you read a file with out storing it all in memorey? <michealo@ozemail.com.au>
    Re: Creating a Perl app.  Help with installation? <mcnuttj@dnps-linux1.telecom.missouri.edu>
    Re: Creating a Perl app.  Help with installation? <ilya@martynov.org>
    Re: file problem... <mgjv@tradingpost.com.au>
    Re: file problem... <bart.lateur@pandora.be>
    Re: file problem... <admin@asarian-host.net>
    Re: modify arguments in a sub / function... <mgjv@tradingpost.com.au>
    Re: Newbie question <goldbb2@earthlink.net>
        Perl and AIM <jimjones@optonline.net>
    Re: Prototype Mismatch Error <newsgroup_mike@ultrafusion.co.uk>
    Re: question for array operation <mgjv@tradingpost.com.au>
    Re: question for array operation <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 24 Nov 2001 23:02:15 -0600
From: "Jake Fan" <jake@chaogic.com>
Subject: A Perl Bug?
Message-Id: <9tpu3e$66l$1@Masala.CC.UH.EDU>

Take a look at this strange problem:

########################################

#!/usr/bin/perl
use v5.0;

$x[0] = $x[0] || !@x && "x";
print "$x[0]\n";
undef @x;

$x[0] ||= !$#x+1 && "x";
print "$x[0]\n";
undef @x;

$x[0] ||= !@x && "x";
print "$x[0]\n";
undef @x;

########################################

Supposedly, all three code sections should do the same thing, but the last
one didn't work out as expected.  Anyone had the same experience or know it
documented somewhere?  I know this may look trivial, but it is still an
undesired "feature by design" (read: bug).





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

Date: Sun, 25 Nov 2001 15:26:51 +1100
From: "nathan" <michealo@ozemail.com.au>
Subject: can you read a file with out storing it all in memorey?
Message-Id: <_L_L7.18507$li3.205594@ozemail.com.au>

i was wondering if you can read all of a file line by line with out storing
it in memorey ?




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

Date: 24 Nov 2001 23:07:08 GMT
From: <mcnuttj@dnps-linux1.telecom.missouri.edu>
Subject: Re: Creating a Perl app.  Help with installation?
Message-Id: <9tp96s$unh$1@dipsy.missouri.edu>

brian d foy <comdog@panix.com> wrote:

>> New way:
>> use JScan::convert;
>> use JScan::getmods;
>> use JScan::gettype;

> [you shouldn''t use all lowercase module names since those
> are reserved by Perl :)]

Yeah, I know.  I renamed and moved them at the same time.  Now I
have packages with names like 'convert'.  Many of them like 'getmods'
can just become 'GetMods', but the ones with really generic names like
'convert' will have to become 'JConvert', I think.

> this actually isn't that bad if you use MakeMaker.  simply
> put all of yor modules in a flat directory in your distribution, 
> say 'lib', then use the PM key to WriteMakefile to tell make
> where to put then in blib.  If you decide to change the structure
> all you fix are the package declarations and Makefile.PL.  you
> don't have to move around files in the distribution.

> WriteMakefile( 
>     ...stuff...
>     PM => {
>         'lib/JScan.pm'   => '$(INST_LIBDIR)/Jscan.pm',
>         'lib/Convert.pm' => '$(INST_LIBDIR)/Jscan/Convert.pm',
>          },
>     ...stuff...
>     );

Well, JScan is 'jscan' (a script), not JScan.pm (a module), but I
digress...

What I've done so far is move all of the modules to lib/JScan/*.pm and
the jscan script to bin/jscan.  The PM key in Makefile.PM is not yet
defined.  I may need to do that at some point.  More below...

> If you wanted to get really fancy, Makefile.PL could walk through
> lib, look at the package names of all of the .pm files, and build
> PM for you.  i started doing that (along with some MANIFEST
> tricks) because a project would add new functionality by
> adding modules.  if i dropped a module into lib, my Makefile.PL
> figured it out.  i then, quite accidently, discovered that 
> it was almost trivial to affect the installation layout by
> just changing the package declarations inside the module
> files themselves ;)

Yup.  I believe in letting the computer do as much work as possible,
which is why personal stubbornness lost to MakeMaker.  :-)

I've already found this to be extremely useful:

find . -type f | stripleadingdotslash - | sort > MANIFEST

Stripleadingdotslash takes a filename as an argument, opens that file
and strips the leading './' off each line, then prints that line to
STDOUT.  Just a little perl thingy I wrote.  I have another just like
it to strip off leading white space.

The next step, as you say, would be to write something more 
interesting that would find the files and write up a quick 
Makefile.PL.  I'm still working on getting MakeMaker to do what I want
yet.  Once I figure it out, I'll automate *that* and I'll just be set.

:-)

--J

"Say!  There really *is* more than one way to do it..."


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

Date: 25 Nov 2001 04:24:54 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Creating a Perl app.  Help with installation?
Message-Id: <87y9kvd4m1.fsf@abra.ru>

>>>>> On 24 Nov 2001 23:07:08 GMT, <mcnuttj@dnps-linux1.telecom.missouri.edu> said:

MC> Yup.  I believe in letting the computer do as much work as possible,
MC> which is why personal stubbornness lost to MakeMaker.  :-)

MC> I've already found this to be extremely useful:

MC> find . -type f | stripleadingdotslash - | sort > MANIFEST

MC> Stripleadingdotslash takes a filename as an argument, opens that file
MC> and strips the leading './' off each line, then prints that line to
MC> STDOUT.  Just a little perl thingy I wrote.  I have another just like
MC> it to strip off leading white space.

You can just write MANIFEST.SKIP and use 'make manifest' for automatic
generation of MANIFEST. See 'perldoc ExtUtils::Manifest'

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)          TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Sun, 25 Nov 2001 10:20:52 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: file problem...
Message-Id: <slrna00aqk.to2.mgjv@martien.heliotrope.home>

On Sat, 24 Nov 2001 07:34:41 -0800,
	Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> MAGiC MANiAC^mTo wrote:
>> my script is this :
>  
>> the results are :
>  
>> '200112
>> ''200114
> 
>> but the results must be:
>  
>> '200112'
>> '200114'
> 
> 
> A presumption is made your last line data entry
> has a trailing newline character.

presumption? sheesh.

> #!perl

no -w. No use strict. Bad examples.

> print "Content-type: text/plain\n\n";

Ridiculous.

> while (<DATA>)
>  {
>   substr ($_, -1, 1, "'\n");

This is just simply moronic.

Martien
-- 
Do not pay any attention to what Godzilla says. It is a troll, and has 
no decent working knowledge of Perl or programming in general. Search 
groups.google.com to see a history of its posts and replies to these posts.


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

Date: Sat, 24 Nov 2001 23:47:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: file problem...
Message-Id: <t1c00uonq3qhk7qi8a3q3hovb6jhiltoa8@4ax.com>

Uri Guttman wrote:

>  M> foreach (@members) {
>  M>     print "\'$_\'\n";
>  M> }
>
>no need for the \. the whole point of using different quote chars is so
>you don't have to escape the other quote chars.

Er, no. The point of having both '"' and "'" as quote characters is that
both have a different behaviour: double quotes allow interpolation,
while everything between single quotes, apart from backslashes in front
of backslashes and single quotes, are taken as is (yes, even  '\n').

You're right that the backslashes are not needed here (apart from the
one in front of the "n"...) because of the different quoting chars. And,
the reason you quote is the raison d'être for the existence of
alternative q() and qq() operators for quoting, with any delimiters you
like.

-- 
	Bart.


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

Date: Sun, 25 Nov 2001 02:06:47 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: file problem...
Message-Id: <XmYL7.86424$qx2.5339827@bin5.nnrp.aus1.giganews.com>

"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7vgg09jc0.fsf@home.sysarch.com...

> >>>>> "M" == Mark  <admin@asarian-host.net> writes:
>
>   M> foreach (@members) {
>   M>     print "\'$_\'\n";
>   M> }
>
> no need for the \. the whole point of using different quote chars
> is so you don't have to escape the other quote chars.

True enough, :)

- Mark




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

Date: Sun, 25 Nov 2001 10:21:39 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: modify arguments in a sub / function...
Message-Id: <slrna00as3.to2.mgjv@martien.heliotrope.home>

On Sat, 24 Nov 2001 10:05:46 -0800,
	Godzilla! <godzilla@stomp.stomp.tokyo> wrote:

[snip of usual Godzilla drivel]

Martien
-- 
Do not pay any attention to what Godzilla says. It is a troll, and has 
no decent working knowledge of Perl or programming in general. Search 
groups.google.com to see a history of its posts and replies to these posts.


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

Date: Sat, 24 Nov 2001 22:08:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Newbie question
Message-Id: <3C0060C6.CCE86DF0@earthlink.net>

mike wrote:
> 
> Laocoon <Laocoon@eudoramail.com> wrote:
> 
> [looking for shortcuts/better tools/etc. for newbie code]
> 
> >hmmm.. maybe this one?
> 
> Okay, my friend, if you say so.  Thanking you all in advance
> for your interest and help . . .
> 
> Mike
> 
> #!/usr/local/bin/perl

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

# always enable warnings, always use strict.

> #  Inputs IP addresses from log file,
> #  parses for Nimda hits and outputs
> #  IPs to file.
> . . .
> 
> # Attempt to open log file; die if it doesn't happen.
> 
> open (LOG, $LogPath) || die "Can't open $LogPath: $!\n";
> 
> # Loop through log file a line at a time and extract the
> # entry information.
> 
> $n=0;
> 
> while (<LOG>)
>     {
> ($ClientIP, $Dummy, $Date, $Time, $SvcName, $SvrName,
> $SvrIP, $CPUTime, $BytesRecv, $BytesSent, $SvcStatus,
> $NTStatus, $Operation, $Target) = split (/,/);
> 
> # Store Log Information and increment counter.
> 
>     $ClientIPArray[$n] = $ClientIP;
>     $DummyArray[$n] = $Dummy;
>     $DateArray[$n] = $Date;
>     $TimeArray[$n] = $Time;
>     $SvcNameArray[$n] = $SvcName;
>     $SvrNameArray[$n] = $SvrName;
>     $SvrIPArray[$n] = $SvrIP;
>     $CPUTimeArray[$n] = $CPUTime;
>     $BytesRecvArray[$n] = $BytesRecv;
>     $BytesSentArray[$n] = $BytesSent;
>     $SvcStatusArray[$n] = $SvcStatus;
>     $NTStatusArray[$n] = $NTStatus;
>     $OperationArray[$n] = $Operation;
>     $TargetArray[$n] = $Target;
>     $n++;
> 
>     }                 # end while (<LOG>)

Yuck.  What disgusting looking code.  Fourteen arrays, where one would
have sufficed.

Also, for parsing csv data, it's often a good idea to use a module
designed for it.  As soon as you have data with either newlines or
commas embeded in it, you'll thank yourself for already having the
module.

use Text::CSV_XS;

my $csv = Text::CSV_XS->new;
my @fields = qw(ClientIP Dummy Date Time
    SvcName SvrName SvrIP CPUTime BytesRecv
    BytesSent SvcStatus NTStatus Operation Target);
my @data;
while( my $row = $csv->getline(\*LOG) ) {
   my %row; @row{@fields} = @$row;
   push @data, \%row;
}

At this point, you can access the data using, eg, $data[$n]{CPUTime}.

Also, note that I don't need a $n variable.

> close (LOG);          # close the log file.
> 
> # Separate out the Nimda hits and store IP numbers
> #for those hits in an array
> 
> $TotalHits = $n;
> $Hit = 0;
> @IPArray = ();
> @NonDupIP = ();
> $p = 0;
> $j = 0;
> 
> open(HOST, ">$hostlog") || warn "Can't open output $hostlog:
> $!\n";
> 
> for ($n = 0; $n < $TotalHits; $n++)
>     {
>     chop ($TargetArray[$n]);

You should be using chomp, not chop... but nevermind, this whole loop is
ugly, and could be done better a different way.

>     if ($TargetArray[$n] eq $Default)
>         {
>         $IPArray[$Hit] = $ClientIPArray[$n];
>         $Hit++;
>         }
>     }

This is a really dumb looking way of doing grep.  So why not use grep?

my @targets = grep { $$_{Target} eq $Default } @data;
my @IPArray = map $$_{ClientIP}, @targets;

The data was already chomped inside of getline.

You don't need the @targets temporary array, but it does make it a bit
clearer to for a newbie to read and understand.

> 
> # Loop through array and remove duplicates
> 
> for ($n = 0; $n < $Hit; $n++)
>     {
>     $Duplicate = 0;
>     for ($p = $n + 1; $p < $Hit; $p++)
>         {
>         if ($IPArray[$n] eq $IPArray[$p])
>             {
>             $Duplicate = 1;
>             last;
>             }
>         }
>     if ($Duplicate == 0)
>         {
>         $NonDupIP[$j] = $IPArray[$n];
>         $j++;
>         }
>     }

Yuck!  Blech!  You're thinking in C, not in Perl.

If you want to remove duplicates, do something like this:

my @NonDupIP = do { my %seen; grep !$seen{$_}++, @IPArray };

Wasn't that easy?

> for ($n = 0; $n < $j; $n++)
>     {
>     print HOST "$NonDupIP[$n]\n";
>     }

foreach my $ip ( @NonDupIp ) {
    print HOST $ip, "\n";
}


my $j = scalar @NonDupIp;

> print HOST "There are $j nonduplicate IPs\n";
> print HOST "J = $j\n";
> 
> #       Create list of Nimda Log Hits
> 
> for ($p = 0; $p < $j; $p++)
>     {
>     print HOST "\n";
>     for ($n = 0; $n < $TotalHits; $n++)
>         {
>         if ($NonDupIP[$p] eq $ClientIPArray[$n])
>             {
>             print HOST "$ClientIPArray[$n] etc.
>             }
>         }
>     }

What's in the etc. ?  Assuming you print out other stuff than the client
ips [ie, if you print out some of the other pieces of data that we
stuffed into @data], then... hmm, I guess that that @targets array will
be useful after all.

foreach my $row (@targets) {
    print HOST "$$row{ClientIP} etc.\n";
}

Where etc. might contain $$row{Target}, $$row{Operation}, etc.

>
> close HOST;
> end;

end?  What the heck is that?  Maybe you mean exit?

-- 
Klein bottle for rent - inquire within.


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

Date: Sun, 25 Nov 2001 04:06:34 GMT
From: "Bob Martin" <jimjones@optonline.net>
Subject: Perl and AIM
Message-Id: <e7_L7.64923$636.10018394@news02.optonline.net>

I'm trying to make an Eliza based AIM robot with the Net::AIM module.  The
page http://www.webreference.com/perl/tutorial/13/3.html has the same thing
I want to do, but their implementation does not work for me.  I have copied
some of the code to make this (this part is exactly the same).  I am unable
to get the array to print the correct information, however.


me: yo
robot: test1 ARRAY(0x827d760) test2   test3  test4
Net::AIM::Event=HASH(0x827d784)

The code that produces this message is:

sub on_im {
   my ($self,$event) = @_;
   my ($nick) = $event->from;
   print $event->dump;
   my @args = $event->args;
      $self->send_im($nick, "test1 $args[0] test2 $args[1] test3 $args[2]
test4 $event");
#    $self->send_im($nick, $mybot->transform($args[2]));
}

The following error message appears when the robot receives a message:

  Use of uninitialized value at ./eliza7.txt line 64, <DATA> chunk 466 (#1)

Line 64 is the line that starts with $self->send_im....


The following information appears on the terminal window also:

TYPE: im_in                             FORMAT:
FROM: me
TO:
Args:
        0: me
        1: F
        2: <HTML><BODY BGCOLOR="#004000"><B><FONT COLOR="#ffff00"
FACE="System">
test</B></FONT></BODY></HTML>





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

Date: Sat, 24 Nov 2001 19:31:22 GMT
From: "Mike Mackay [Ultrafusion]" <newsgroup_mike@ultrafusion.co.uk>
Subject: Re: Prototype Mismatch Error
Message-Id: <eASL7.5868$zh6.699916@news1.cableinet.net>

Thanks very much for the help, adding 'get' the the module line has stopped
it from throwing up the error.

Regards,
Mike Mackay.




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

Date: Sun, 25 Nov 2001 10:13:44 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: question for array operation
Message-Id: <slrna00ad8.to2.mgjv@martien.heliotrope.home>

On Sat, 24 Nov 2001 08:39:47 -0800,
	Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
    
[The usual stupid drivel snipped]


> Godzilla!
> -- 
>       - The CLPM Troll

Indeed you are.

> TEST SCRIPT:

The usual lowest quality code one can find anywhere.

> #!perl

As usual, no -w, and no use strict

> print "Content-type: text/plain\n\n";

As usual, outputting useless stuff.

> print "Unknown Position:\n\n";
> 
> $delete_word = "dog";
> 
> @Array = qw (cat dog chicken lizard catfish dog t-rex);
> 
> $position = 0;
> 
> for (@Array)
>  {
>   if ($_ eq $delete_word)
>    { splice (@Array, $position, 1); }
>   $position++;
>  }

$ man perlsyn
[SNIP]
           LABEL foreach VAR (LIST) BLOCK
           LABEL foreach VAR (LIST) BLOCK continue BLOCK
[SNIP]
       The "foreach" keyword is actually a synonym for the "for"
       keyword, so you can use "foreach" for readability or "for"
       for brevity.
[SNIP]
       If any part of LIST is an array, "foreach" will get very
       confused if you add or remove elements within the loop
       body, for example with "splice".   So don't do that.
[SNIP]

Go on. Keep showing us what a wonderful Perl programmer you really are.

Martien
-- 
Do not pay any attention to what Godzilla says. It is a troll, and has 
no decent working knowledge of Perl or programming in general. Search 
groups.google.com to see a history of its posts and replies to these posts.


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

Date: Sun, 25 Nov 2001 10:15:31 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: question for array operation
Message-Id: <slrna00agj.to2.mgjv@martien.heliotrope.home>

On Sat, 24 Nov 2001 09:10:24 -0800,
	Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Kit wrote:
> 
> (snipped)
> 
>> eg.@abc=(cat,dog,chicken).
> 
> Regarding an issue separate from my first article,
> your choice of array format is not all that wise.
> 
> Research and read about array formats, specifically
> alphabetical characters versus numerical characters.

> @abc = (cat, dog, chicken, t-rex);

This has nothing to do with arrays, you ninny. And if you finally
learned to use -w and strict on your programs, you would know, because
Perl would tell you what was wrong.

Martien
-- 
Do not pay any attention to what Godzilla says. It is a troll, and has 
no decent working knowledge of Perl or programming in general. Search 
groups.google.com to see a history of its posts and replies to these posts.


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

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


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