[19735] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1930 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 15 00:05:30 2001

Date: Sun, 14 Oct 2001 21:05:07 -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: <1003118707-v10-i1930@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 14 Oct 2001     Volume: 10 Number: 1930

Today's topics:
    Re: 20-line webserver in perl ? (Joe Smith)
    Re: 20-line webserver in perl ? <dtweed@acm.org>
        backgrounding a system call <cherbst@hotpop.com>
    Re: backgrounding a system call <spam@thecouch.homeip.net>
    Re: backgrounding a system call (Logan Shaw)
    Re: Change Last Modified for all files in a directory (Garry Williams)
    Re: Check Syntax (Garry Williams)
    Re: Check Syntax <mjcarman@home.com>
    Re: Check Syntax <gclark@wavetel.com>
        HTML / SNMP <gclark@wavetel.com>
    Re: HTML / SNMP <spam@thecouch.homeip.net>
        newbie <--question about variables <kteegirl24@hotmail.com>
    Re: newbie <--question about variables (Garry Williams)
    Re: newbie <--question about variables <jeff@vpservices.com>
    Re: newbie <--question about variables <jeff@vpservices.com>
    Re: newbie <--question about variables <mjcarman@home.com>
    Re: newbie <--question about variables <kteegirl24@hotmail.com>
    Re: Perl and Win32 <wyzelli@yahoo.com>
        Search engine script needs to run for Mac & PC on a cd <dmartin119@home.com>
    Re: Search engine script needs to run for Mac & PC on a <spam@thecouch.homeip.net>
    Re: Specifying a range of values <mjcarman@home.com>
    Re: Specifying a range of values (Logan Shaw)
    Re: split into filename and extension (need help before (Joe Smith)
    Re: Using Split (Garry Williams)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 15 Oct 2001 01:48:45 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: 20-line webserver in perl ?
Message-Id: <9qdf9t$3bj$1@nntp1.ba.best.com>

In article <m3ofnbebei.fsf@mumonkan.sunstarsys.com>,
Joe Schaefer  <joe+usenet@sunstarsys.com> wrote:
>Besides, you can cram an awful lot of stuff in 4 lines of Perl :)
>
>Joe Schaefer
>-- 
>$v="HTTP/1.0";$/="\r\n"x2;socket S,2,1,6;bind(S,pack'Snx12',2,80)||die;listen S
>,8;for(*STDOUT=*C;accept(C,S);close){($_)=<C>=~/^GET\s+(\S+)/ or print("$v 400"
>.$/),next;$ENV{QUERY_STRING}=s/\?(.+)//?$1:'';s/%(..)/chr hex$1/eg;-x$_?print(
>"$v 200$/")&&do$_:open(F,$_)?print"$v 200$/",<F>:print"$v 404$/"for$ARGV[0].$_}
        ^^
Bug ----^^

I tried running your 4-line web server (after changing S,2,1,6 to
S,2,2,6 for SVR4/Solaris) and found a bug.  When I went to
http://localhost/home/joe/public_html/test.cgi it ran the executable
perl script OK, but the "Content-type: text/html" line was displayed.

The first 16 characters of the last line should be
"v 200\n")&&do$_
so that the CGI's headers will be processed as headers.

Of course, no one should ever run that 4-line web server as it stands.
It treats the pathname part of the URL as a Unix absolute pathname,
allowing anyone to use "http://yourhostname/etc/passwd" to read your files.

So, yes, it is possible to write an HTTP server in less than 20 lines of
perl, but such simple-minded servers have no security at all.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Mon, 15 Oct 2001 02:15:51 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: 20-line webserver in perl ?
Message-Id: <3BCA4573.B879181E@acm.org>

Joe Smith wrote:
> Of course, no one should ever run that 4-line web server as it stands.
> It treats the pathname part of the URL as a Unix absolute pathname,
> allowing anyone to use "http://yourhostname/etc/passwd" to read your files.

No, it concatenates it with $ARGV[0], assuming I understand it correctly.
If you don't give an argument, of course, you get the behavior you describe.
Even still, plenty of "../" will get you pretty much anywhere in the system.
A chroot would help provide some isolation.

-- Dave Tweed


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

Date: Mon, 15 Oct 2001 03:10:58 GMT
From: "chris" <cherbst@hotpop.com>
Subject: backgrounding a system call
Message-Id: <pan.2001.10.14.23.08.07.870.1399@hotpop.com>

This is perl, version 5.005_03 built for i386-linux

If I want to do something like this:

system('mpg123','-vw','track.$i.wav','$_');

and not have the perl script wait for mpg123 to exit, how can I do this
without using a shell?

I would just do this:

system('mpg123 -vw track.$i.wav $_ &');

but it won't work when $_ has quotes or paranthesis.


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

Date: Sun, 14 Oct 2001 23:14:42 -0400
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: backgrounding a system call
Message-Id: <vwsy7.10053$7f5.658753@weber.videotron.net>


"chris" <cherbst@hotpop.com> wrote in message
news:pan.2001.10.14.23.08.07.870.1399@hotpop.com...
> This is perl, version 5.005_03 built for i386-linux
>
> If I want to do something like this:
>
> system('mpg123','-vw','track.$i.wav','$_');
>
> and not have the perl script wait for mpg123 to exit, how can I do this
> without using a shell?
>
> I would just do this:
>
> system('mpg123 -vw track.$i.wav $_ &');

'     will not read and interpolate variables
"     will

system("mpg123 -vw track.$i.wav $_ &");
is probably what you want.


>
> but it won't work when $_ has quotes or paranthesis.




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

Date: 14 Oct 2001 22:30:29 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: backgrounding a system call
Message-Id: <9qdl8l$759$1@charity.cs.utexas.edu>

In article <pan.2001.10.14.23.08.07.870.1399@hotpop.com>,
chris <cherbst@hotpop.com> wrote:
>This is perl, version 5.005_03 built for i386-linux
>
>If I want to do something like this:
>
>system('mpg123','-vw','track.$i.wav','$_');
>
>and not have the perl script wait for mpg123 to exit, how can I do this
>without using a shell?

system() is roughly equivalent to fork() followed by the child calling
exec() and the parent calling wait().  The wait() is what makes the
parent not continue until the child finishes.  So do the same thing,
but don't call wait() in the parent:

    if ($pid = fork)
    {
	die "Can't fork()\n" if $pid == -1;

	# we are the parent

	# (do nothing)
    }
    else
    {
	# we are the child
	exec ('mpg123', '-vw', "$track.$i.wav", $_);

	# control normally doesn't reach this point.

	die "Couldn't exec 'mpg123'";
    }

Hope that helps.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Mon, 15 Oct 2001 01:26:33 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Change Last Modified for all files in a directory
Message-Id: <slrn9skeq8.ip8.garry@zfw.zvolve.net>

On Sun, 14 Oct 2001 23:50:55 GMT, What A Man ! <whataman@home.com> wrote:
> My script below does not change the last modified date. 

I don't believe you.  

> The error
> message says there is no such file. What am I doing wrong?
> 
> # Change last mod date for all files in "test" directory
> 
> chdir "test";
> opendir THISDIR, "." or die "Can't Open Directory: $!";
> @files = grep !/^\.\.?$/, readdir THISDIR;
>    foreach $file(@files) {
>      $now=time;
>       utime $now, $now, @files; 
>     };
>     die "Cannot change utime: $!";
> closedir THISDIR;

As a matter of fact, the code above changes the times on all of the
files in the directory as many times as there are files in the
directory.  

In spite of your bizarre indentation, the call to die() will happen
every time the script is run -- after all of the files have had their
mtime changed (more than once!).  The value of $! is residual -- not
as a result of a check for an error.  

It turns out that utime() will not return a false value, if *any* file
in the list has been successfully changed.  (See the utime() section
of the perlfunc manual page.)  

The thing you probably want to do is: 

  #!/usr/bin/perl -w
  use strict;
  chdir "test"         or die "can't chdir to test: $!\n";;
  opendir THISDIR, "." or die "can't open test: $!\n";

  my $err;
  my $now = time;
  foreach ( grep !/^\.\.?$/, readdir THISDIR ) {
    utime $now, $now, $_
    or warn "can't touch test/$_: $!\n" and $err = 1;
  }

  closedir THISDIR;
  exit(1) if $err;

-- 
Garry Williams


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

Date: Mon, 15 Oct 2001 01:29:56 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Check Syntax
Message-Id: <slrn9skf0k.ip8.garry@zfw.zvolve.net>

On Sun, 14 Oct 2001 23:05:43 GMT, Geoff Clark <gclark@wavetel.com> wrote:
> Could someone please check my syntax when they get a moment.  Thank you,

That's a pretty degrading thing to ask of people.  

[snip lots of un-indented code without warnings enabled.]

-- 
Garry Williams


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

Date: Mon, 15 Oct 2001 02:27:24 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: Check Syntax
Message-Id: <3BCA4903.50909@home.com>

Geoff Clark wrote:
 >

> Could someone please check my syntax when they get a moment.  Thank you,


Why are you asking us to do it? Let perl check it for you:

perl -cw myscript.pl

-mjc



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

Date: Mon, 15 Oct 2001 02:36:44 GMT
From: "Geoff Clark" <gclark@wavetel.com>
Subject: Re: Check Syntax
Message-Id: <0Zry7.8877$%B.1199240@bin1.nnrp.aus1.giganews.com>

The reason I am asking is because when I run the script it is failing on the
STDOUT.  I was hoping you or someone could assist.  If this is not possible,
well then thank you anyway.

Geoff
"Geoff Clark" <gclark@wavetel.com> wrote in message
news:bToy7.501816$Lw3.30476548@news2.aus1.giganews.com...
> Could someone please check my syntax when they get a moment.  Thank you,
>
> Geoff Clark
>
>
>
> #!'C:\Perl\bin\Perl.exe'
>
> use strict;
> use vars qw($session $error $response $host $addr $filename $ip $UnitName
> $bestau);
>
>
> use Net::SNMP;
>
> foreach $host (1 .. 10) {
> my $addr = "10.1.66.$host";
>
> ($session, $error) = Net::SNMP->session(
> -hostname => $addr,
> -community => 'public',
> -timeout => '2',
> -retries => '1'
> );
>
>
> if (!defined($session)) {
> printf("ERROR: %s.\n", $error);
> next;
> }
>
> my $ip = '1.3.6.1.4.1.710.3.3.11.5.0';
> my $UnitName = '1.3.6.1.4.1.710.3.3.10.3.0';
> my $bestau = '1.3.6.1.4.1.710.3.3.6.23.1.0';
>
> $response = $session->get_request($ip, $UnitName , $bestau);
>
>
> if (!defined($response)) {
> printf("ERROR: %s.\n", $session->error());
> $session->close();
> next;
> }
>
> printf("IP Address = %s, Unit Name = %s, Best AU Support = %s\n",
> $response->{$ip},
> $response->{$UnitName},
> $response->{$bestau}
> );
>
>
> while ($filename = <*.secret>) {
> open (WORDLIST, $filename) || die "can't open $filename: $!",
> while ($ip = <WORDLIST>);
> chomp ($ip);
> $UnitName = <WORDLIST>;
> chomp ($UnitName);
> $bestau = <WORDLIST>;
> chomp ($bestau);
> write;
> }
> close (WORDLIST);
>
>
> $session->close();
> }
>
> format STDOUT =
> @<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<
> $ip, $UnitName, $bestau
> .
>
> format STDOUT_TOP =
> Page @<<
> $%
>
> WaveTel Network Operations - Best AU Support
> 0 = Disabled 1 = Enabled
>
> IP Address Unit Name Best Au Support
> ============== ======================== ===============
> .
> exit 0;
>
>
>
>




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

Date: Mon, 15 Oct 2001 03:04:19 GMT
From: "Geoff Clark" <gclark@wavetel.com>
Subject: HTML / SNMP
Message-Id: <Tmsy7.503347$Lw3.30578980@news2.aus1.giganews.com>

I have a simple question I hope.  I need to create a web interface to some
SNMP devices.  My question to you is, what is the best method to accomplish
this.  Example:  I need to be able select different form buttons and run
certain scripts.  I hope this makes sence.  One example would be if I have a
field for an IP Address and I have a button that says ping.  I want the
button to run a ping script and return the results to a text field.

Geoff




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

Date: Sun, 14 Oct 2001 23:16:11 -0400
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: HTML / SNMP
Message-Id: <Txsy7.10073$7f5.659866@weber.videotron.net>

Get apache (web server)

Write a perl script that acts as a CGI using the CGI.pm library

have the perl script do what you want it to do, depending on browser input,
and return back the results you want it to return.

"Geoff Clark" <gclark@wavetel.com> wrote in message
news:Tmsy7.503347$Lw3.30578980@news2.aus1.giganews.com...
> I have a simple question I hope.  I need to create a web interface to some
> SNMP devices.  My question to you is, what is the best method to
accomplish
> this.  Example:  I need to be able select different form buttons and run
> certain scripts.  I hope this makes sence.  One example would be if I have
a
> field for an IP Address and I have a button that says ping.  I want the
> button to run a ping script and return the results to a text field.
>
> Geoff
>
>




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

Date: Mon, 15 Oct 2001 01:53:20 GMT
From: Katie Craven <kteegirl24@hotmail.com>
Subject: newbie <--question about variables
Message-Id: <3BCA404C.7020903@hotmail.com>

I am the newest of newbies, so I appreciate anyones patience and help. I 
was wondering if anyone could tell me how to turn information submitted 
into a form into a variable.

Thank you in advance



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

Date: Mon, 15 Oct 2001 02:00:55 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: newbie <--question about variables
Message-Id: <slrn9skgqn.ir5.garry@zfw.zvolve.net>

On Mon, 15 Oct 2001 01:53:20 GMT, Katie Craven <kteegirl24@hotmail.com> wrote:
> I am the newest of newbies, so I appreciate anyones patience and help. I 
> was wondering if anyone could tell me how to turn information submitted 
> into a form into a variable.

Keypunch it?  

-- 
Garry Williams


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

Date: Sun, 14 Oct 2001 19:28:27 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: newbie <--question about variables
Message-Id: <3BCA49CB.FA6FA7B2@vpservices.com>

Katie Craven wrote:
> 
> I am the newest of newbies, so I appreciate anyones patience and help. I
> was wondering if anyone could tell me how to turn information submitted
> into a form into a variable.

There is a module for that called CGI.pm, it comes with perl and has
lots of documentation with it.  In short:

#!/usr/local/bin/perl -wT
use strict;
use CGI;
my $q = CGI->new;
my $squash = $q->param('squash');
#
# $name is now a variable in your script that holds whatever the user
entered
# into the form field with the name 'squash'
 ...

-- 
Jeff



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

Date: Sun, 14 Oct 2001 19:30:35 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: newbie <--question about variables
Message-Id: <3BCA4A4B.C1AC4FEE@vpservices.com>

Jeff Zucker wrote:
> 
> my $squash = $q->param('squash');
> #
> # $name is now a variable

Er, I mean $squash is now a variable ...

-- 
Jeff



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

Date: Mon, 15 Oct 2001 02:34:23 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: newbie <--question about variables
Message-Id: <3BCA4AA6.3080902@home.com>

Katie Craven wrote:
 >

> I am the newest of newbies, so I appreciate anyones patience and help. I 
> was wondering if anyone could tell me how to turn information submitted 
> into a form into a variable.


I assume that your talking about a CGI script.

#!/usr/local/bin/perl -w
use strict;
use CGI qw/:standard/;

my $value = param('name');
#...

I suggest a thorough reading of the CGI manpage.

-mjc



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

Date: Mon, 15 Oct 2001 02:43:56 GMT
From: Katie Craven <kteegirl24@hotmail.com>
Subject: Re: newbie <--question about variables
Message-Id: <3BCA4C28.7010107@hotmail.com>

Thanks everyone for the suggetions.. solved my problem!

Michael Carman wrote:

> Katie Craven wrote:
>  >
> 
>> I am the newest of newbies, so I appreciate anyones patience and help. 
>> I was wondering if anyone could tell me how to turn information 
>> submitted into a form into a variable.
> 
> 
> 
> I assume that your talking about a CGI script.
> 
> #!/usr/local/bin/perl -w
> use strict;
> use CGI qw/:standard/;
> 
> my $value = param('name');
> #...
> 
> I suggest a thorough reading of the CGI manpage.
> 
> -mjc
> 



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

Date: Mon, 15 Oct 2001 10:45:07 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Perl and Win32
Message-Id: <1Eqy7.31$791.247@wa.nnrp.telstra.net>

"Darlene Murphy" <deemurphy_us@yahoo.com> wrote in message
news:dbcc56f5.0110131415.18e14c79@posting.google.com...
> I am trying to get perl to run under WinME.  I have done web sites on
> unix systems with perl and they work fine.
>
> For WinMe I am using WinSite and ActiveState Perl.  It dose not
> recognize #!g:\perl\bin\perl.  What should I use?  Also how do we put
> comments in our perl scripts.
>
> I have also tryed on W2K Adv. Server using IIE or IBM's Servers and
> ActiveState Perl and get the same results.
>
> #1g:\perl\bin\perl comes up in my window after a submit and then the
> rest of the file which is garbage.

Sounds like the server is not configured to recognise Perl.  Normally that
is specified as something to do with the .pl rather than the shebang, which
Windows itself ignores.  (Perl will still use command switches like -w on
the shebang line, and Apache for Windows uses it too).  I have no experience
with WinSite though, having only used IIS which uses the application
configuration section to specify how to handle Perl programs.

I would check an y FAQs and server groups for WinSite as the most likely
source of help.  Otherwise, if you can, change the server to one which is
easier to set up (the web server that is).

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Mon, 15 Oct 2001 02:28:45 GMT
From: "JerryGarciuh" <dmartin119@home.com>
Subject: Search engine script needs to run for Mac & PC on a cd
Message-Id: <xRry7.114699$707.57833758@news2.rdc2.tx.home.com>

Hi all,
I am trying to craft a search engine for a small database which will be on a
cd and will be run only on the cd.  I have written a little engine that
could in perl but I am having trouble finding a crossplatform solution for
running the 'server' on the cd.  TinyWeb and MicroWeb and all the others
seem to be strictly Win32.  Has anyone here done this?  I don't know Java at
all.  Is javascript (of which I have cookbook knowledge) my only resort?
Advice?
TIA,
jg


--
My name is Inigo Montoya...

www.nolaFlash.com




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

Date: Sun, 14 Oct 2001 22:53:22 -0400
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: Search engine script needs to run for Mac & PC on a cd
Message-Id: <vcsy7.9778$7f5.639575@weber.videotron.net>


"JerryGarciuh" <dmartin119@home.com> wrote in message
news:xRry7.114699$707.57833758@news2.rdc2.tx.home.com...
> Hi all,
> I am trying to craft a search engine for a small database which will be on
a
> cd and will be run only on the cd.  I have written a little engine that
> could in perl but I am having trouble finding a crossplatform solution for
> running the 'server' on the cd.  TinyWeb and MicroWeb and all the others
> seem to be strictly Win32.  Has anyone here done this?  I don't know Java
at
> all.  Is javascript (of which I have cookbook knowledge) my only resort?
> Advice?
> TIA,
> jg

What kind of "server" are you talking about ? A web server ?

You might as well write your own in Perl and incorporate it into your entire
database. That will give you a lot of control and it's not as hard as it
sounds (There was a minimal HTTP server in perl posted somewhere ~ 7 or so
lines) as well I'm sure someone wrote a module to facilitate HTTP daemon
needs.


>
>
> --
> My name is Inigo Montoya...
>
> www.nolaFlash.com
>
>




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

Date: Mon, 15 Oct 2001 02:24:26 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: Specifying a range of values
Message-Id: <3BCA4850.7060500@home.com>

Logan Shaw wrote:

> Philip Newton  <nospam.newton@gmx.li> wrote:
>>
>> Perl6 will let you do the 'maths' thing and go straight for
>>
>>   if( $X < $score < $Y) { ... }
> 
> Say it ain't so!


Yep. Larry talks about this in the most recent Apocalyspe:

http://www.perl.com/pub/a/2001/10/02/apocalypse3.html

> How does it deal with the fact that that expression is ambiguous?


DWIMery, of course. This is Perl, after all. :)

According to the RFC:

       0 <= $x < 10

   is DWIMmed to:

       0 <= $x && $x < 10

-mjc



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

Date: 14 Oct 2001 22:25:28 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Specifying a range of values
Message-Id: <9qdkv8$72o$1@charity.cs.utexas.edu>

In article <3BCA4850.7060500@home.com>,
Michael Carman  <mjcarman@home.com> wrote:

>Logan Shaw wrote:

>> Philip Newton  <nospam.newton@gmx.li> wrote:
>>> Perl6 will let you do the 'maths' thing and go straight for
>>>
>>>   if( $X < $score < $Y) { ... }

>> Say it ain't so!

>Yep. Larry talks about this in the most recent Apocalyspe:
>
>http://www.perl.com/pub/a/2001/10/02/apocalypse3.html

So since it's an RFC, is there any way I can contribute C's that
they've R'ed F people to make[1]?

The RFC proposes that it applies to "comparisons", but it doesn't make
it clear whether that includes just comparisons for equivalence, or
just for ordering, or for both.

  - Logan

[1]  comments they've requested for people to make.
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Mon, 15 Oct 2001 02:13:25 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: split into filename and extension (need help before I go insane)
Message-Id: <9qdgo5$3cm$1@nntp1.ba.best.com>

In article <3BC45EDF.488E7018@oracle.com>,
Graham Wood  <Graham.T.Wood@oracle.com> wrote:
>($name,$ext)= $filename =~  /(.+)\.{1}([^.]+)?$/;

Using {1} is superfluous.  The whole thing can be simplified to
  ($name,$ext) = $filename =~ /(.*)\.(.*)/;
which says to put as many characters into $name as possible, up to but
not including the last period in the string.  Set $ext to whatever is
left over after the last period in the string.  Greediness wins.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Mon, 15 Oct 2001 01:42:22 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Using Split
Message-Id: <slrn9skfnu.ip8.garry@zfw.zvolve.net>

On Sun, 14 Oct 2001 16:55:17 -0700, Dustin Keys <keysd@cs.pdx.edu> wrote:
> I am trying to pul the idle times for al the users currently on a system.  I
> am using the who -u command to generate this list and I am stuffing it into
> a string variable.  All I want is to create a list with each element being
> one idle time.  For example.
> 
> prasad     pts/15       Oct 14 15:41  0:02  14123
> (pdxproxy.jf.intel.com)
> prasad     pts/16       Oct 14 16:07  0:32  14371
> (pdxproxy.jf.intel.com)
> keysd      pts/13       Oct 14 13:19   .       12283
> (sirius.cs.pdx.edu)
> prasad     pts/4         Oct 14 16:38   .       14571
> (pdxproxy.jf.intel.com)
> keysd      pts/14       Oct 14 14:32  0:20  12989
> (dsl-209-162-200-134.easystreet.com)
>                                                        ^^^ This is the
> coloum I want stored into a list like,
> 
> "0.02", "0.32", ".", ".". "0.20"
> 
> I have tried split using many different patters but have yet to make my
> desired results.  Any ideas?

Have you tried " ", the default?  

  my @idles;
  open(WHO, "who -u |") or die "can't exec who -u: $!\n";
  while (<WHO>) {
    push @idles, (split)[5];
  }
  close(WHO)
    or die "who ended with status: $?",
	   $! ? " and close ended with $!\n" : "\n";
  # Process @idles

-- 
Garry Williams


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

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


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