[17490] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4910 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 17 09:05:44 2000

Date: Fri, 17 Nov 2000 06:05:11 -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: <974469910-v9-i4910@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 17 Nov 2000     Volume: 9 Number: 4910

Today's topics:
    Re: Beginners blues. (Gwyn Judd)
    Re: Beginners blues. <wyzelli@yahoo.com>
    Re: Beginners blues. <johngros@Spam.bigpond.net.au>
    Re: Beginners blues. <kstep@pepsdesign.com>
    Re: Beginners blues. (dionysus)
    Re: Chart graphing suitable for web page <rick.delaney@home.com>
    Re: Checking Writable Sockets on Solaris 2.6 nobull@mail.com
        Concatenating files <MPEDDLE@uk.ibm.com>
    Re: Concatenating files (Gwyn Judd)
    Re: CRC Check <bart.lateur@skynet.be>
    Re: Date <wyzelli@yahoo.com>
    Re: Date <bart.lateur@skynet.be>
    Re: Difference between recv() and read() nobull@mail.com
        filehandle to array richard_dobson@my-deja.com
    Re: filehandle to array <kstep@pepsdesign.com>
    Re: How do I ensure that only a single instance of my s (Anno Siegel)
    Re: How to get client address from accept() <nickco3@yahoo.co.uk>
    Re: How to get name of current opened file in while(<>) <yosikim@lgeds.lg.co.kr>
        long array to multivalue hash richard_dobson@my-deja.com
    Re: long array to multivalue hash <rick.delaney@home.com>
    Re: long array to multivalue hash <jeffp@crusoe.net>
    Re: long array to multivalue hash nobull@mail.com
    Re: Newbie Perl Question <jeffp@crusoe.net>
    Re: Newbie Perl Question <geoff-at-farmline-dot-com@127.0.0.1>
    Re: Newbie Perl Question <geoff-at-farmline-dot-com@127.0.0.1>
    Re: No idea about perl, Long post, short question (Anno Siegel)
        NOBODY COULD HELP US??????????????????????????????????? <artax@shineline.it>
    Re: Regex to zero pad an IP address <lincmad001@telecom-digest.zzn.com>
        Unix, Perl and the TOP command <vivekvp@spliced.com>
    Re: Unix, Perl and the TOP command (Rafael Garcia-Suarez)
        Use of uninitialized value in hash slice <johnlin@chttl.com.tw>
    Re: Use of uninitialized value in hash slice <rick.delaney@home.com>
    Re: Use of uninitialized value in hash slice <rick.delaney@home.com>
    Re: Use of uninitialized value in hash slice (Anno Siegel)
    Re: Why are references useful? (Anno Siegel)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 17 Nov 2000 08:07:25 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Beginners blues.
Message-Id: <slrn919ppq.7vo.tjla@thislove.dyndns.org>

I was shocked! How could John Boy Walton <johngros@Spam.bigpond.net.au>
say such a terrible thing:
>Right almost fixed.
>#!E:/Millenium Programs/perl/bin/Perl
>$pwd=$time;
>open(ftpdat,'>C:/Program Files/G6 FTP
>Server/ftpdatabase/johngros\@bigpond.net.au.txt');
>print ftpdat $pwd;
>close ftpdat;
>
>Technically it should work but the file is not there.

Obviously it shouldn't work, because the file is not :)

>Should it be "open(ftpdat,'+>>C:/Program Files/G6 FTP
>Server/ftpdatabase/johngros\@bigpond.net.au.txt');"?

Beats me. Does windows even support files with carriage returns in the
middle of the name? By the way that was:

open FILE, '>filename' or die "Cannot open file: $!";

NOT:

open FILE, '>filename';

Also you should start your scripts with the following:

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

(Except you can replace the first line with the correct path to your
perl binary if you like).

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
IBM Advanced Systems Group -- a bunch of mindless jerks, who'll be first
against the wall when the revolution comes...
		-- with regrets to D. Adams


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

Date: Fri, 17 Nov 2000 17:49:05 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Beginners blues.
Message-Id: <VM5R5.1$pd1.415@vic.nntp.telstra.net>

"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:cs5R5.10855$tU2.90173@news-server.bigpond.net.au...
> Right almost fixed.
> #!E:/Millenium Programs/perl/bin/Perl
> $pwd=$time;
> open(ftpdat,'>C:/Program Files/G6 FTP
> Server/ftpdatabase/johngros\@bigpond.net.au.txt');
> print ftpdat $pwd;
> close ftpdat;
>
> Technically it should work but the file is not there.
> Should it be "open(ftpdat,'+>>C:/Program Files/G6 FTP
> Server/ftpdatabase/johngros\@bigpond.net.au.txt');"?
>

No, for a couple of reasons, the main one being that spaces can't be
passed to the command shell.

You will need to use the real path (c:/progra~1/ etc etc etc/)

If you put the

or die "unable to create file $!"

message as suggested by Gwyn, you might get some hint about why it isn't
working.  $! is the Perl variable which contains the last operating
system error, such as why the file could not be opened.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





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

Date: Fri, 17 Nov 2000 09:36:24 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Beginners blues.
Message-Id: <s_6R5.10938$tU2.91322@news-server.bigpond.net.au>

I have made all the suggested changes, -w, use strict,
 or die "Cannot open file: $!";
Now perl expects me to declare my variables the two books I have give
descriptions of strict but give no hint how to declare the variables.
So the script won't compile.




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

Date: Fri, 17 Nov 2000 05:49:40 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Beginners blues.
Message-Id: <8v32fl$5ed$1@slb7.atl.mindspring.net>

"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:s_6R5.10938$tU2.91322@news-server.bigpond.net.au...
> I have made all the suggested changes, -w, use strict,
>  or die "Cannot open file: $!";
> Now perl expects me to declare my variables the two books I have give
> descriptions of strict but give no hint how to declare the variables.
> So the script won't compile.
>

1) Read the documentation on 'use strict'.
2) See Private Variables via my() in the perlsub manpage.

Perl variables are either dynamically scoped (visible throughout the current
package) or lexically scoped using the 'my' operator.  The 'use strict'
pragma will produce a compile time error unless you explicitly declare your
variables using one of the methods below.  While explicitly declaring your
variables may seem like a pain, it's a lot easier than tracking down bugs
caused by typos or inadvertantly changing a value somewhere else in your
program.

In general, you should normally use 'my' to declare your variables as
lexically scoped.  The 'my' operator restricts the visibility of these
variables to the current block of code - a variable defined in a loop or in
a subroutine is not visible outside of that scope.  This allows you to
create as many $x's and $i's as you need, without worrying about naming
conflicts.  Be careful using global variables - these should only be used
for constants and package-wide configuration settings.  Actually constants
should be declared as subs or with the 'use constant' pragma.  Another case
for dynamically scoped variables is where the variable must be visible
across package boundaries.

# Dynamically scoped with 'use vars'
# These are global variables vidsible throughout the
# current package

use vars qw($G_SCALAR, @G_ARRAY, %G_HASH);

# Dynamically scoped with explicit package name

$main::SomeValue = 'ABC';

# Dynamically scoped using 'local'

local %hash; # You probably want to use 'my' instead

# Lexically scoped using 'my'

my $s;
my $x= 'Some Value';
my ($var1, $var2, $var3) = ('Value1', 'Value2', 3);

print "$x\n";

while (<>) {
    my $x= 123; # this 'x' is only visible in the while loop
    print "$x\n";
}





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

Date: Fri, 17 Nov 2000 13:59:01 GMT
From: dionysus39@hotmail.com (dionysus)
Subject: Re: Beginners blues.
Message-Id: <3a1538ed.163893847@nntp.unsw.edu.au>


>
>No, for a couple of reasons, the main one being that spaces can't be
>passed to the command shell.
umm....no-one told me (or my copy of perl) that.....
I have never had any problems....but then I always use 

open(IN, "> c:\\some directory\\some file.txt") or die;

for single quotes it would not work, yeah....

-d


>
>You will need to use the real path (c:/progra~1/ etc etc etc/)
>
>If you put the
>
>or die "unable to create file $!"
>
>message as suggested by Gwyn, you might get some hint about why it isn't
>working.  $! is the Perl variable which contains the last operating
>system error, such as why the file could not be opened.
>
>Wyzelli
>--
>($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
>it around');
>for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
>$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
>
>
>


------------------------------------------------------------
"One World, one Web, one Program" - Microsoft promotional ad
"Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .


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

Date: Fri, 17 Nov 2000 12:58:50 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Chart graphing suitable for web page
Message-Id: <3A152EC3.C8D95838@home.com>

[posted & mailed]

Oscar Vallarino wrote:
> 
> I am looking for some off-the-shelf software that can generate simple
> 2-D graph charts from number series, and produce output in GIF or PNG
> format suitable to display on a web page.
[snip]
> I've looked for some Perl modules and found GD.pm as a possible
> candidate. Unfortunately this is a low level package that would
> require we design and write charting code on top of it to get charts
> similar to what Microsoft Excel can do (which is what I am using).

No need for that since it has already been done.  Check out GD::Graph.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: 17 Nov 2000 08:13:28 +0000
From: nobull@mail.com
Subject: Re: Checking Writable Sockets on Solaris 2.6
Message-Id: <u9snoqlxxz.fsf@wcl-l.bham.ac.uk>

"Jimmy" <someone@compugenx.com> writes:

> Hello,
>     using IO::Socket on Solaris 2.6 everytime I attempt a socket call with a
> die like:
> 
> $client->send($data) || die "It didint work!\n";
> 
> if the above code is executed after $client has disconnected, my die will
> never be called, instead an error of "Broken Pipe" is sent to STDERR and the
> progrma is terminated.

Actually I think you'll find it's the other way around and therein is
the clue.

Broken pipe is not a Perl error.  The Perl process is terminating on
an untrapped SIGPIPE, it is the shell that wails "Broken Pipe" when
one of its children dies and it sees SIGPIPE on the death certificate.

Simply trap or ignore SIGPIPE.

{
  local $SIG{PIPE} = 'IGNORE';
  $client->send($data) || die "It didint work!\n";
}

{
  local $SIG{PIPE} = sub { die "It didint work!\n"; };
  $client->send($data);
}

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 17 Nov 2000 09:30:17 -0000
From: Mark <MPEDDLE@uk.ibm.com>
Subject: Concatenating files
Message-Id: <t19ul9amlf8r62@corp.supernews.com>

Hi all,

I was wondering if it was at all possible to concatenate FILES in Perl, i 
have not found a function to do this. 
Do i have to read each file into an array first, and then concatenate 
arrays - this would be very slow, especially it involved large data 
quantities.

Any Ideas ?

Thanks,
Mark

--
Posted via CNET Help.com
http://www.help.com/


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

Date: Fri, 17 Nov 2000 12:55:41 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Concatenating files
Message-Id: <slrn91aama.dhp.tjla@thislove.dyndns.org>

I was shocked! How could Mark <MPEDDLE@uk.ibm.com>
say such a terrible thing:
>Hi all,
>
>I was wondering if it was at all possible to concatenate FILES in Perl, i 
>have not found a function to do this. 

It is very simple. You can do it in one line if you like:

perl -pe1 file1 file2 file3 > outputfile

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Never argue with a man who buys ink by the barrel.


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

Date: Fri, 17 Nov 2000 09:55:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: CRC Check
Message-Id: <s00a1tsjv1i1c1kaph8scjol4lngsjh1gp@4ax.com>

EM wrote:

>is there a way to do it with activeperl?
>i cannot install modules from cpan

There are several versions of String::CRC available on Activestate's
site. Pick the one for your Perl version.
(<www.activestate.com/packages>, likely in the x86 subdir)

-- 
	Bart.


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

Date: Fri, 17 Nov 2000 18:17:27 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Date
Message-Id: <tg6R5.5$pd1.386@vic.nntp.telstra.net>

"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:qvo91tsak6ggsnfgrqfpmipkkg8e6he201@4ax.com...
> Wyzelli wrote:
>
> >$today = sprintf
> >"%02d/%02d/%4d",(localtime)[3],(localtime)[4]+1,(localtime)[5]+1900;
> >
> ># Note my use of European Date format and 4 digit year - just to be
> >different
>
> Not just that. In Europe, we have the habit of putting the day first,
> month second.
>

Eh?  What is the above then?  A ham sandwich?  :)

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Fri, 17 Nov 2000 11:57:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Date
Message-Id: <567a1tcq671gq0o2a2njfg1gi953180q9v@4ax.com>

Wyzelli wrote:

>> ># Note my use of European Date format and 4 digit year - just to be
>> >different
>>
>> Not just that. In Europe, we have the habit of putting the day first,
>> month second.
>>
>Eh?  What is the above then?  A ham sandwich?  :)

I was appending something to your comment, for the Americans. It most
probably wasn't clear from the code alone -- unless you know by heart
just what (localtime)[3] and (localtime)[4] are.

-- 
	Bart.


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

Date: 17 Nov 2000 08:41:37 +0000
From: nobull@mail.com
Subject: Re: Difference between recv() and read()
Message-Id: <u9ofzelxu1.fsf@wcl-l.bham.ac.uk>

qlos@my-deja.com writes:

> What is the difference between functions recv() and read()?

AFAIK recv() with zero FLAGS argument is the same as sysread() without
an OFFSET argument but with different semantics for the return value.

> In my program I can't read socket using recv(). It gets
> nothing. When use read() everything looks be fine.

Maybe a previous read() already read the data into the buffer.  Mixing
stdio and non-stdio IO is not something to do lightly.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 17 Nov 2000 09:42:51 GMT
From: richard_dobson@my-deja.com
Subject: filehandle to array
Message-Id: <8v2uiq$4lq$1@nnrp1.deja.com>

hello, please could anyone tell me why the following doesn't seem to be
working?


open (DB,"database.txt");

@array=<DB>;

print "<pre>\n";
print STDOUT font({-size=>'3', -color=>'#800000'},@array);
print "</pre>";

thanks in advance

Rich


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 17 Nov 2000 06:01:03 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: filehandle to array
Message-Id: <8v335m$gug$1@slb2.atl.mindspring.net>

<richard_dobson@my-deja.com> wrote in message
news:8v2uiq$4lq$1@nnrp1.deja.com...
> hello, please could anyone tell me why the following doesn't seem to be
> working?
>
>
> open (DB,"database.txt");
>
> @array=<DB>;
>
> print "<pre>\n";
> print STDOUT font({-size=>'3', -color=>'#800000'},@array);
> print "</pre>";
>
> thanks in advance
>
> Rich

Try testing the result of the open command - are you sure the file was
opened?
BTW, you don't need to specify STDOUT in the print statement unless you have
selected a different filehandle somwhere else in the script.

The following code should work:

use strict;
use warnings;

use CGI qw(:standard);

open (DB,"database.txt") or die "Can't open file: $!";

my @array=<DB>;

print "<pre>\n";
print font({-size=>'3', -color=>'#800000'},@array);
print "</pre>";





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

Date: 17 Nov 2000 10:25:22 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How do I ensure that only a single instance of my script is running (in Linux)?
Message-Id: <8v312i$hkc$1@lublin.zrz.tu-berlin.de>

 <grishaa@my-deja.com> wrote in comp.lang.perl.misc:

>You probably want to use something like
>$numOfInstances = `ps -Af | grep $0 | grep -v grep | wc -l`;

Useless use of wc: "grep -vc".

Anno


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

Date: Fri, 17 Nov 2000 11:47:09 +0000
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: How to get client address from accept()
Message-Id: <3A151ABD.19AEC31A@yahoo.co.uk>

bowman wrote:

> Nick Condon <nickco3@yahoo.co.uk> wrote:
>
> !The client's IP address is in $iaddr, $name contains the client's
> !hostname, $port is the originating port (probably not very interesting).
>
> Just as a footnote: it is possible for the client to designate a port and
> bind it, rather than using a ephemeral port assigned by the OS. This
> technique is sometimes used so the server can examine the client's port
> for authentication purposes.
>

Really? What does it authenticate?
--
Nick



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

Date: Fri, 17 Nov 2000 18:19:31 +0900
From: Yongsik Kim <yosikim@lgeds.lg.co.kr>
Subject: Re: How to get name of current opened file in while(<>)
Message-Id: <3A14F823.84F1C090@lgeds.lg.co.kr>

$ARGV

confer http://www.perl.com/pub/doc/manual/html/pod/perlvar.html

Derek Ross wrote:
> 
> Hello,
> 
> I'm new to perl and I'm having a problem I can't seem to find the answer
> to.
> 
> I'm using a while(<>) loop to process a file... is there a way to get
> the current filename that is being processed?
> 
> I'm calling perl from the commandline, and processing files by the batch
> using wildcards for the file name, like so:
> 
> perl -w process.pl *.txt > output.html
> 
> Any help would be greatly appreciated.
> 
> Derek Ross


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

Date: Fri, 17 Nov 2000 12:51:29 GMT
From: richard_dobson@my-deja.com
Subject: long array to multivalue hash
Message-Id: <8v39kg$c5m$1@nnrp1.deja.com>

hello, i have an array that i would like to turn into a hash with each
key having three values. The 1st line of the array (in each block of 4
values) will be the key each time.
I have tried the following but to no avail:

while (($rate,$date,$descr,$who)=@array){
$hash{$rate}=[$date,$descr,$who];
}

please could anyone give any tips?

thanks in advance
Richard


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 17 Nov 2000 13:09:47 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: long array to multivalue hash
Message-Id: <3A153154.6B3FBD65@home.com>

[posted & mailed]

richard_dobson@my-deja.com wrote:
> 
> hello, i have an array that i would like to turn into a hash with each
> key having three values. The 1st line of the array (in each block of 4
> values) will be the key each time.
> I have tried the following but to no avail:
> 
> while (($rate,$date,$descr,$who)=@array){
> $hash{$rate}=[$date,$descr,$who];
> }

Looks mostly reasonable.  It's impossible to tell from this small
snippet what "to no avail" means.
 
> please could anyone give any tips?

Post a larger (but not too large) snippet and say what it is supposed to
do as well as what it actually does.  For example, what behaviour are
you observing that makes you think the above code is wrong?

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Fri, 17 Nov 2000 08:35:02 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: long array to multivalue hash
Message-Id: <Pine.GSO.4.21.0011170833310.265-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 17, richard_dobson@my-deja.com said:

>while (($rate,$date,$descr,$who)=@array){
>$hash{$rate}=[$date,$descr,$who];
>}

I think your problem is that you have the array with sets of 4 elements in
a row, and you want to grab them and remove them -- your while loop grabs
the first set over and over again.  You need to remove them, too.

I'd start at the back, then, for pop()ing elements is faster than
unshift()ing them:

  while (($a,$b,$c,$d) = splice(@array, -4)) {
    $hash{$a} = [$b,$c,$d];
  }

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: 17 Nov 2000 13:23:22 +0000
From: nobull@mail.com
Subject: Re: long array to multivalue hash
Message-Id: <u9lmuilol1.fsf@wcl-l.bham.ac.uk>

richard_dobson@my-deja.com writes:

> I have tried the following but to no avail:
> 
> while (($rate,$date,$descr,$who)=@array){
> $hash{$rate}=[$date,$descr,$who];
> }

The assignment in the while condition does not consume elements from
@array so it reads the first 4 elements over and over.  (Oh and you've
also missed out a my()). What you probably wanted to do is shift off
the elements 4 at a time:

while (my ($rate,$date,$descr,$who) = splice @array,0,4 ) { 
   $hash{$rate}=[$date,$descr,$who];
}

BTW: TMTOWTDI - many of which may be more efficient than this simple
solution.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 17 Nov 2000 08:17:07 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Newbie Perl Question
Message-Id: <Pine.GSO.4.21.0011170816270.265-100000@crusoe.crusoe.net>

On Nov 17, Martien Verbruggen said:

>>   perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/' in > out
>
>Very sneaky. One typo, though.
>
>perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/e' in > out

D'oh, d'oh, d'oh.  I was spending so much time making sure the inner
workings were right, and I plum forgot the damn /e.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Fri, 17 Nov 2000 13:28:48 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Newbie Perl Question
Message-Id: <8v3bqg$3a3$1@soap.pipex.net>

"Jeff Pinyan" <jeffp@crusoe.net> wrote in message
news:Pine.GSO.4.21.0011162245220.265-100000@crusoe.crusoe.net...
> On Nov 16, dcfor3@hotmail.com said:
> >abc,def,ghi
> >123,456,789
>
> There's a sneaky solution that is derived from a merlyn answer:
>   perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/' in > out
> It works by changing the newline to ",[NEXT LINE],[NEXT LINE]\n".  This is
> called "clever". ;)

Can you explain a bit further? I -think- I understand but I'm a bit lost as
to how you specify three per line...

Cheers

Geoff
(still a perl-newbie...)




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

Date: Fri, 17 Nov 2000 13:30:52 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Newbie Perl Question
Message-Id: <8v3bua$3cc$1@soap.pipex.net>


"Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1> wrote in message
news:8v3bqg$3a3$1@soap.pipex.net...
> "Jeff Pinyan" <jeffp@crusoe.net> wrote in message
> news:Pine.GSO.4.21.0011162245220.265-100000@crusoe.crusoe.net...
> > On Nov 16, dcfor3@hotmail.com said:
> > >abc,def,ghi
> > >123,456,789
> >
> > There's a sneaky solution that is derived from a merlyn answer:
> >   perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/' in > out
> > It works by changing the newline to ",[NEXT LINE],[NEXT LINE]\n".  This
is
> > called "clever". ;)
>
> Can you explain a bit further? I -think- I understand but I'm a bit lost
as
> to how you specify three per line...

And as -soon- as I hit "send" it hit me what you meant. Sorry...

Geoff




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

Date: 17 Nov 2000 10:52:14 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: No idea about perl, Long post, short question
Message-Id: <8v32ku$hl9$1@lublin.zrz.tu-berlin.de>

Simon Watkins <siwatkins@iee.org> wrote in comp.lang.perl.misc:
>"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message

 ...

>> Your score in my killfile just plummeted below visibility level. At
>> least you've reached that goal.
>
>Great, I'll not have to read any more inflammatory posts from you.

Oh dear.  How long have uou been active on usenet again?

Anno


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

Date: Fri, 17 Nov 2000 10:53:58 +0100
From: "Federico" <artax@shineline.it>
Subject: NOBODY COULD HELP US??????????????????????????????????????????????????
Message-Id: <3a150047_1@news.telnetwork.it>


Hi all,

    I have a big problem and no idea how to solve it. I would be very happy
is somebody could catch this little challenge and give me an help.


   The problem is the following: I have to download a page using the perl
module LWP (the URL change at every request) ans its address could be this
one:
http://service.bfast.com/bfast/click?bfmid=1921220&siteid=35414878&bfpid=086
162036941&bfmtype=movies If you try with IE or Netscape you could raalize
that (and maybe this is one of the causes of the problem!) before you obtain
the answer page there will be TWO rediretcs. Anyway using the browser all
work correctly.

    On the countrary usind the metod GET with the Perl module LWP:


         use LWP::UserAgent;

         my($interfaccia) = new LWP::UserAgent;
         my($richiesta);
         $interfaccia->agent('Mozilla/5.0');
         $interfaccia->timeout(30);

          $richiesta=HTTP::Request-> new('GET' =>
'http://service.bfast.com/bfast/click?bfmid=1921220&siteid=35414878&bfpid=08
6162036941&bfmtype=movies' );

        $richiesta->content_type('application/x-www-form-urlencoded');

          $risultato = $interfaccia->request($richiesta);
          $temp = $risultato->as_string;

          print $temp;

(it could be i have done mistakes or fogotten something coping the code, but
the original one is correct it works well with all the other addreses)

you will botain an ERROR MESSAGE from the host server of this kind (this is
the print of the headers):


HTTP/1.1 200 OKCache-Control: no-cacheConnection: Keep-AliveDate: Thu, 16
Nov 2000 12:23:29 GMTPragma: no-cachePragma: no-cacheServer:
Microsoft-IIS/5.0Content-Length: 19386Content-Type: text/htmlContent-Type:
text/html; charset=windows-1252Expires: Thu, 01 Dec 1994 16:00:00
GMTExpires: Wed, 11 Aug 1999 07:00:00 GMTExpires: 0Client-Date: Thu, 16 Nov
2000 12:23:30 GMTClient-Peer: 199.2.223.1:80Set-Cookie:
SITESERVER=ID=83d9b27a6d8d7e3e7e4e9f73e1540cc7; expires=Monday, 01-Jan-2035
00:00:00 GMT; path=/; domain=.800.comTitle: Incorrect Access Permission

What i can understand is that the remote server does a cookies cache control
and since the module LWP hasn't this function the server returns an error.

    Does somebody know how to solve this problem?


    I have tried  to lunch two requests: the first to obtain a cookies-set
and the second one with the cookies-set just obtained to get the wanted
response page  without the cache controll considering that the cookies were
already present. I have done it adding before the previus code this
instructions


         use HTTP::Cookies;
         my($biscottino) = new HTTP::Cookies;

and after the same previus code

          $biscottino->add_cookie_header($richiesta);
          $risultato = $interfaccia->request($richiesta);
        $temp=$risultato->as_string.$temp;

but it doesn't work!


    Please if somebody knows how to solve this problem ... could it write me
at artax@shineline.it ???

    Thank you, sorry for my terrible english, from italy ^_^

        Federico Bari.












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

Date: Fri, 17 Nov 2000 03:44:16 -0800
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: Regex to zero pad an IP address
Message-Id: <171120000344166352%lincmad001@telecom-digest.zzn.com>

In article <slrn9193ja.rk.tadmc@maxim.metronet.com>, Tad McClellan
<tadmc@metronet.com> wrote:

> On Thu, 16 Nov 2000 12:13:03 +1300, Peter Sundstrom 
>    <peter.sundstrom@eds.com> wrote:
> >
> >Jack Applin <neutron@jackbert.fc.hp.com> wrote in message
> >news:8uv3us$5ea$1@fcnews.fc.hp.com...
> 
> >>   $ip =~ s/(\d+)/sprintf "%03d",$1/eg;
> >
> >Now that's a good trick.  I didn't realise you could use sprintf in a regex.
>                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> You cannot use sprintf in a regex.
> 
> The first part of s/// is a regex. The second part of s/// is NOT a regex.
> 
> In the replacement part of s///e you can use not only sprintf(),
> but any Perl code at all!

The other problem, though, is that if you zero-pad an IP address, some
programs will interpret it as octal.

For instance, http://0177.0177.0177.0177 is equivalent to
http://127.127.127.127

However, http://10.1.2.3 and http://010.001.002.003 are very different.

You can also freely intermingle them, as in http://127.127.0177.127

Of course, something like http://0193.127.127.127 may have unwanted
results, because of the '9' in the octal part.


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

Date: Fri, 17 Nov 2000 09:12:53 GMT
From: vivekvp <vivekvp@spliced.com>
Subject: Unix, Perl and the TOP command
Message-Id: <8v2sqj$3eu$1@nnrp1.deja.com>

 Hello,

I have a Unix system.  I want to check for zombie processes.  The way I
am determining this is those processes that have a time of greater than
30 minutes.

CPU TTY   PID USERNAME PRI NI   SIZE    RES STATE    TIME %WCPU  %CPU
COMMAND
 0 pty/ttyq5 13611 xxxxx   156 20  2708K  1608K sleep    0:00  1.97
1.85 fglgo
 0 pty/ttyta 13657 xxxxx  178 20   952K   548K run      0:00  2.56  1.41
top
 0 pty/ttypc 11104 xxxxx 156 20  2656K  1576K sleep    0:02  1.41  1.40
fglgo
 0 rroot    19 yyyyy     100 20     0K     0K sleep   56:33  0.91  0.91
netisr
 0 pty/ttyta 13638 eeeee  168 20   320K   260K sleep    0:00  0.81  0.57
csh
 0 rroot 13666 lp       158 20   628K   188K sleep    0:00  1.74  0.51
repsep2
 0 rroot     3 ttttt     128 20     0K     0K sleep   33:39  0.44  0.44
statdaemo
 1 pty/ttyrf 11934 fffff 156 20  2608K  1528K sleep    0:01  0.32  0.32
fglgo
 0 pty/ttyt6 13613 iiiii   156 20  2636K  1552K sleep    0:00  0.33
0.31 fglgo
 0 rroot 13665 lp       158 20   400K   420K sleep    0:00  0.98  0.29
lpsched

I use the top command to check - is there any way to check the TOP
command every 15 minutes - put the output into a perl file - parse to
the 10th column - find the time - check to see if it is >30minutes and
kill the process if so?

I am not sure how to mix Unix and PERL...
Any ideas?

Thanks,

V
--
He who fights and runs away, lives to run another day!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 17 Nov 2000 10:22:44 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Unix, Perl and the TOP command
Message-Id: <slrn91a1oi.4v9.rgarciasuarez@rafael.kazibao.net>

vivekvp wrote in comp.lang.perl.misc:
> 
> I have a Unix system.  I want to check for zombie processes.  The way I
> am determining this is those processes that have a time of greater than
> 30 minutes.

Bad. Daemons or X servers have typically a time larger than 30 minutes
(if the machine's uptime is long enough).

On some systems (Solaris, Linux), ps -ef gives you the '<defunct>'
indication for zombie processes. But you don't have specified which Unix
flavor you're using. So we can't help you with you system's specific ps
command.

The perl program you want may get the info from ps, something like the
following one-liner :
  perl -e 'kill 9, map { (split " ",$_)[1] } grep /<defunct>/,`ps -ef`;'

(see perdoc -f kill, perldoc -f map, etc. for the functions, and perldoc
perlop for the backquotes).

The run a command at scheduled times, read your system's manpages about
crontab.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 17 Nov 2000 13:31:16 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Use of uninitialized value in hash slice
Message-Id: <8v2g1f$4fn@netnews.hinet.net>

Dear all,

In the following program:

    my %hash = (undef=>1, 2=>3);
    print $hash{undef},$hash{2},"\n";  # prints 13

Fine.  But if we change it into

    print @hash{undef,2},"\n";

we get -w warning messages and a different result:

    Use of uninitialized value in hash slice at line 3.
    Use of uninitialized value in print at line 3.
    3

It prints 3, not 13.
Do you think this is something inconsistent?

Thank you.

John Lin





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

Date: Fri, 17 Nov 2000 12:55:36 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Use of uninitialized value in hash slice
Message-Id: <3A152E01.67842155@home.com>

[posted & mailed]

John Lin wrote:
> 
> Dear all,
> 
> In the following program:
> 
>     my %hash = (undef=>1, 2=>3);
>     print $hash{undef},$hash{2},"\n";  # prints 13
> 
> Fine.  But if we change it into
> 
>     print @hash{undef,2},"\n";
> 
> we get -w warning messages and a different result:
> 
>     Use of uninitialized value in hash slice at line 3.
>     Use of uninitialized value in print at line 3.
>     3
> 
> It prints 3, not 13.
> Do you think this is something inconsistent?

Not really.  As you see, a plain bareword as a hash key will be
automatically quoted, so in your first example "undef" is treated as the
string instead of the function.

In the second example, you don't have a plain bareword, but an
expression as the hash key.  Perl doesn't automatically quote each term
of the expression, nor would you want it to.  Since it is a hash slice,
the expression is evaluated in list context and the lookup is done for
each of the two keys undef() and 2.

If you had written

    print $hash{undef,2},"\n";

then you might expect the key expression to be evaluated in scalar
context so that it prints 3.  Normally that instinct would be correct,
except that Perl special-cases comma separated terms in a scalar hash
key as

    join $;, undef, 2

This is a leftover from the days before Perl had references and it was
the only way to have multi-dimensional hashes.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Fri, 17 Nov 2000 13:03:46 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Use of uninitialized value in hash slice
Message-Id: <3A152FEB.DADAD04@home.com>


Anno Siegel wrote:
> 
> John Lin <johnlin@chttl.com.tw> wrote in comp.lang.perl.misc:
> >Dear all,
> >
> >In the following program:
> >
> >    my %hash = (undef=>1, 2=>3);
> >    print $hash{undef},$hash{2},"\n";  # prints 13
> 
> Remember a hash key is always a string (unlike a value, which can be
> any scalar), so undef isn't really a valid hash key.  Perl converts
> undef to the empty string '', and that's the key you really get.

Not in this case where a lot of quoting is going on.  C<undef> is not a
valid hash key but 'undef' is.

See my followup to John.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: 17 Nov 2000 13:28:17 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Use of uninitialized value in hash slice
Message-Id: <8v3bph$htu$1@lublin.zrz.tu-berlin.de>

Rick Delaney  <rick.delaney@home.com> wrote in comp.lang.perl.misc:
>
>Anno Siegel wrote:
>> 
>> John Lin <johnlin@chttl.com.tw> wrote in comp.lang.perl.misc:
>> >Dear all,
>> >
>> >In the following program:
>> >
>> >    my %hash = (undef=>1, 2=>3);
>> >    print $hash{undef},$hash{2},"\n";  # prints 13
>> 
>> Remember a hash key is always a string (unlike a value, which can be
>> any scalar), so undef isn't really a valid hash key.  Perl converts
>> undef to the empty string '', and that's the key you really get.
>
>Not in this case where a lot of quoting is going on.  C<undef> is not a
>valid hash key but 'undef' is.

Absolutely.  I cancelled the article too late.

Anno


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

Date: 17 Nov 2000 11:25:14 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why are references useful?
Message-Id: <8v34iq$hno$1@lublin.zrz.tu-berlin.de>

 <andrew338@my-deja.com> wrote in comp.lang.perl.misc:
>Perl is my first programming language.  I can do most of the basic
>things and have read about references but don't use them.  I don't see
>why to.  A reference is "a piece of data that refers to another piece
>of data, but I already use $variable to represent a value like "6".

Fine, don't bother.  As long as you don't need references, program
without them.  Once you do need them, it will become clear what
they are good for.

Your objection that $variable holds a value like 6 just fine isn't
quite off the mark.  References to scalars are in fact not often
used.  But if you think of @variable, which can hold not only a
single value but a whole list of them ( 6, 7, 8, 9), the idea of
having a reference to all of them in a single scalar becomes more
interesting.

This is the main use of references in Perl: enabling access to
an array or hash through a single scalar.

Anno


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

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


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