[10571] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4163 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 6 01:07:17 1998

Date: Thu, 5 Nov 98 22:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 5 Nov 1998     Volume: 8 Number: 4163

Today's topics:
    Re: Array Ref Question <b-i-lla@tqs.antispam.com>
    Re: Basic question (Tad McClellan)
    Re: Changing @INC (Tad McClellan)
        Clear screen? (Gustaf Liljegren)
    Re: Clear screen? (Alastair)
    Re: Clear screen? (Peter J. Kernan)
        Comparing ASCII dates <Robert.H.Lowe@X-no.spam-X.lawrence.edu>
    Re: Comparing ASCII dates (brian d foy)
        Help on version 4 and version 5... <rwilliamson@uno.gers.com>
    Re: HELP! alarm doesn't work during gethostbyaddr() (Ken Alexander)
        How: C macro in a extension <anatol@ml.com>
    Re: initializing large list of variables with similar n (Tad McClellan)
    Re: initializing large list of variables with similar n (Ronald J Kimball)
        Need a two way hash (Awrobinson)
    Re: Need a two way hash (Ronald J Kimball)
    Re: ODBC Resource? <tpg@cls.uob.com.sg>
    Re: Odd number of elements? (Peter J. Kernan)
        OLE and ActiveState, Why so slow? <rtrussell@hps-inc.com>
        pass a file directly to stdout? (Brad Fenwick)
    Re: perl questions PLEASE HELP :) (Ronald J Kimball)
        Please help on finding difference between dates. <hovi@mtco.com>
    Re: simple scalar question (Tad McClellan)
    Re: simple scalar question (Ronald J Kimball)
    Re: system(". $file"); #odd result! (Tad McClellan)
        Using recv in Socket programming <arvindk@pa.dec.com>
        what does split do on empty fields? <emschwar@mail.uccs.edu>
    Re: what does split do on empty fields? (Tad McClellan)
    Re: what does split do on empty fields? (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 05 Nov 1998 16:56:56 -0800
From: Bill Adams <b-i-lla@tqs.antispam.com>
Subject: Re: Array Ref Question
Message-Id: <36424958.7CB6410C@tqs.antispam.com>



Ronald J Kimball wrote:

> Brand Hilton <bhilton@tsg.adc.com> wrote:
>
> >    my $array_ref = +['1'];
> > anonymous hashes from blocks, but I don't know what, if anything, "+["
> > does.
> +{} disambiguates an anonymous hash from a block because a block cannot
> be used as the operand of unary +, while an anonymous hash can.

Originally, I was into anonymous hashes and read that +{} is not ambiguous
whereas a plain {} can be; I got into the habit of using +{} when I meant
"anonymous hash" (it was one extra keystroke to prevent a possible bug).
When I started using anonymous arrays, I automatically put the + in front of
[] without having consulted the manual going on the assumption that there
might be an ambiguous case so it would not hurt to put it there.

--Bill Adams







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

Date: Thu, 5 Nov 1998 20:15:11 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Basic question
Message-Id: <f3mt17.c05.ln@flash.net>

mxk164@psu.edu wrote:
: Could anyone help me out with a basic configuation question?

  Sure. We could help with configuring Perl, here in the 
  Perl newsgroup.


: I'm trying to get some Perl and CGI scripts to work, but I don't
: believe they are set as executable, and thus are not running
: when I attempt to load them from my browser. (my browser just
: prompts me with a download box when I try to load the .pl or .cgi
: files.
:   A few notes: I am using Windows NT, the server is capable of

: Any and all help is  greatly appreciated.
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   OK, this will be a really big help in getting questions
   answered on Usenet:

      Ask Perl questions in a Perl newsgroup.

      Ask server questions in a server newsgroup.

   ;-)


      comp.infosystems.www.servers.ms-windows



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 5 Nov 1998 20:36:59 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Changing @INC
Message-Id: <bcnt17.c35.ln@flash.net>

Greg Coit (gbc1@axe.humboldt.edu) wrote:
: We just installed perl 5.005_2 and our scripts return the following
: error when we use any Modules:

: Can't locate LWP/Simple.pm in @INC
: (@INC contains:
:         /usr/local/lib/perl5/5.00502/alpha-dec_osf
:         /usr/local/lib/perl5/5.00502
:         /usr/local/lib/perl5/site_perl/5.005/alpha-dec_osf
:         /usr/local/lib/perl5/site_perl/5.005 .)

: The correct directory is: /usr/local/lib/perl5/site_perl

: Is there anyway to change the @INC globally? (ie. without altering all
: of our scipts).  Or should we:
:     1) Reinstall and provide the correct paths during installation


   Go with number 1.

   (If you meant reinstall perl rather than reinstall the module)

   
   Those paths are set when you build perl. Build perl again.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 06 Nov 1998 01:08:19 GMT
From: gustafl@algonet.se (Gustaf Liljegren)
Subject: Clear screen?
Message-Id: <36424c00.30075048@news.algonet.se>


I'm trying to make a text based configuration script wich consist of a
few menus in a hierarchical system. The script will run in UNIX (I'm
using the Perl interpreter of my ISP in Telnet). If it's not to hard,
I would like to clear the screen between the menus. Like the UNIX
command "clear" or DOS command "cls". If I remember correctly, there
is a clear screen command in C/C++ also, but I can't find this
function in Perl.

Regards

Gustaf Liljegren



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

Date: Fri, 06 Nov 1998 01:46:23 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Clear screen?
Message-Id: <slrn744l5i.55.alastair@calliope.demon.co.uk>

Gustaf Liljegren <gustafl@algonet.se> wrote:
>
>I'm trying to make a text based configuration script wich consist of a
>few menus in a hierarchical system. The script will run in UNIX (I'm
>using the Perl interpreter of my ISP in Telnet). If it's not to hard,
>I would like to clear the screen between the menus. Like the UNIX
>command "clear" or DOS command "cls". If I remember correctly, there
>is a clear screen command in C/C++ also, but I can't find this
>function in Perl.

You could always use the 'system' command. Alternatively, curses might be worth
looking into if you want 'real' terminal based menu system.

HTH.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: 6 Nov 1998 04:15:56 GMT
From: pete@localhost.localdomain (Peter J. Kernan)
Subject: Re: Clear screen?
Message-Id: <71tt5s$t7f$1@pale-rider.INS.CWRU.Edu>

In article <36424c00.30075048@news.algonet.se>,
	gustafl@algonet.se (Gustaf Liljegren) writes:
> 
> I'm trying to make a text based configuration script wich consist of a
> few menus in a hierarchical system. The script will run in UNIX (I'm
> using the Perl interpreter of my ISP in Telnet). If it's not to hard,
> I would like to clear the screen between the menus. Like the UNIX
> command "clear" or DOS command "cls". If I remember correctly, there
> is a clear screen command in C/C++ also, but I can't find this
> function in Perl.
> 
> Regards
> 
> Gustaf Liljegren
> 
>From the Perl Cookbook aka Ram book

use Term::Cap;
$OSPEED=9600;
eval {
  require POSIX;
  my $termios = POSIX::Termios->new();
  $termios->getattr;
  $OSPEED= $termios->getospeed;
};
$terminal= Term::Cap->Tgetent({OSPEED=>$OSPEED});
$clear = $terminal->Tputs('cl');

#...
#in some generic loop now
  print $clear;
-- 
open SIG, "<$ENV{HOME}/.sig"         or die       "sigless!     $!"; 
$sig = do {local $/; <SIG>};         close SIG && print<<"$sig SIG";
        Pete Kernan  CWRU Physics and Statistics Depts
        http://theory2.phys.cwru.edu/~pete
$sig SIG


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

Date: Thu, 05 Nov 1998 19:28:30 -0600
From: Robert Lowe <Robert.H.Lowe@X-no.spam-X.lawrence.edu>
Subject: Comparing ASCII dates
Message-Id: <364250BE.32A0B0@X-no.spam-X.lawrence.edu>

Hi!

Before I re-invent something in a messy way, does anyone have
any tips on how to get the difference between two ASCII dates
in days?  The dates are in DD-MMM-YYYY format.  I suppose it
would trivial if an ASCII date could somehow be converted to
an internal system time, but I don't know if there is such a
mechanism.

TIA,
Robert


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

Date: Thu, 05 Nov 1998 21:22:56 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Comparing ASCII dates
Message-Id: <comdog-ya02408000R0511982122560001@news.panix.com>

In article <364250BE.32A0B0@X-no.spam-X.lawrence.edu>, Robert Lowe <Robert.H.Lowe@X-no.spam-X.lawrence.edu> posted:

> Before I re-invent something in a messy way, does anyone have
> any tips on how to get the difference between two ASCII dates
> in days? 

perhaps one of the Date::* modules?

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 5 Nov 1998 19:24:41 -0800
From: "Rusty Williamson" <rwilliamson@uno.gers.com>
Subject: Help on version 4 and version 5...
Message-Id: <LXt02.104$DA6.22583@news.connectnet.com>

Hi!
I've hit a little problem -- on the dozen or so servers we have at work,
/usr/bin/perl on some systems is version 5, while on others its version 4
and version 5 is /usr/bin/perl5.  We have tons of v4 scripts all starting
out with #!/usr/bin/perl.  What are people doing?

Rusty







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

Date: 6 Nov 1998 01:13:34 GMT
From: kalex@quip.eecs.umich.edu (Ken Alexander)
Subject: Re: HELP! alarm doesn't work during gethostbyaddr()
Message-Id: <71tifu$rao$1@news.eecs.umich.edu>
Keywords: timeout, alarm, gethostbyaddr, signals

In article <F1rIp7.KCD@news.boeing.com>,
Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
>eval {
>  local $SIG{ALRM} = sub { die "timed out" };
>  alarm 3;
>  gethostbyaddr...
>  alarm 0;
>};
>if ($@ =~ /^timed out/) {
>   ...


My problem is that it only works the first time.
(Perl 5.002, Solaris 2.5.1)
My routine looks something like this:

sub ip2hname {
    my($host) = @_;
    my($ip, $hname);
 
    if (not already cached in my lookup table) {
        $ip = pack('C4', split(/\./, $host));
        eval {
            local $SIG{ALRM} = sub { die "dns timeout\n" };
            alarm(10);
            $hname = (gethostbyaddr($ip, 2))[0];
            alarm(0);
        };
        alarm(0);
        warn "DNS timeout on $host\n" if ($@ && $@ =~ /dns/);
    }
    return($hname);
}


I call this routine repeatedly for each IP address in a logfile.
The first time that it takes more than 10 seconds to resolve a name,
the timeout works (it prints the "DNS timeout" and goes on to the next).
After that, however, DNS can hang the routine for up to a minute
(when it hits some other timeout, I believe), and it never prints
that error ever again during the same run of the program.

Why is my 10-second alarm not getting set again after the first time?
What am I doing wrong?

Thanks a lot,
kalex@umich.edu



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

Date: Fri, 06 Nov 1998 11:21:59 +0900
From: Anatol Filin <anatol@ml.com>
Subject: How: C macro in a extension
Message-Id: <36425D47.D724AB4F@ml.com>

Hello,

I need some piece of Perl code to be #ifdef -ed
in a extension module.

In plain script I would use -P option to
pass code through the cpp first. 

Is there way to make it work similarly in a
extension (e.g. using Makefile.PL )?

Thanks
Anatol


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

Date: Thu, 5 Nov 1998 22:09:56 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: initializing large list of variables with similar names
Message-Id: <kqst17.9k5.ln@flash.net>

Ray Bush (rbush@up.net) wrote:
: can i use something like this:

: for $item ( "npdmm" "npddd" "npdyy" "lpmmm"){
:   $($item."f")=$($item);	
: }

: instead of something like this:

: 		$totalfeesf=$totalfees;
: 		$npdmmf=$npdmm;
: 		$npdddf=$npddd;
: 		$npdyyf=$npdyy;
: 		$lpmmmf=$lpmmm;


   Yes.

   1) build the list the way you build a list in Perl:

      for $item ( "npdmm", "npddd", "npdyy", "lpmmm"){  # commas between

      or

      for $item ( qw/npdmm npddd npdyy lpmmm/ ){



   2) use curly brackets instead of parenthesis:

        ${$item."f"}=${$item};



   3) see the "Symbolic references" section in the 'perlref' man page.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 5 Nov 1998 23:55:56 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: initializing large list of variables with similar names
Message-Id: <1di1jdp.1pl1z7f1k9vdomN@bay1-59.quincy.ziplink.net>

Ray Bush <rbush@up.net> wrote:

> can i use something like this:
> 
> for $item ( "npdmm" "npddd" "npdyy" "lpmmm"){
>   $($item."f")=$($item);  
> }

Yes, but only if you insert a comma between list elements, and change
those parentheses to curly braces.

for $item ("npdmm", "npddd", "npdyy", "lpmmm"){
  ${$item."f"}=${$item};  
}

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 6 Nov 1998 02:47:26 GMT
From: awrobinson@aol.com (Awrobinson)
Subject: Need a two way hash
Message-Id: <19981105214726.00139.00004586@ng143.aol.com>

I'm building an application where I have two quantities matched up. In some
cases, I need to use one set as the key to the other. In other cases, I need to
use the second set as the key to the first. Can anyone suggest a convenient way
to do this? Is there a way to use the values in a hash to get to the keys?

TIA...


Andrew Robinson
---
Disclaimer: The opinions expressed are mine alone and do not represent the
views of America Online


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

Date: Fri, 6 Nov 1998 00:34:14 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Need a two way hash
Message-Id: <1di1qfo.18npldn1b32a6zN@bay1-59.quincy.ziplink.net>

Awrobinson <awrobinson@aol.com> wrote:

> I'm building an application where I have two quantities matched up. In some
> cases, I need to use one set as the key to the other. In other cases, I
> need to use the second set as the key to the first. Can anyone suggest a
> convenient way to do this? Is there a way to use the values in a hash to
> get to the keys?

Silly way - walk the hash until you find the value you're using as a key

while (($key, $value) = each %hash) {
  if ($value eq $value_as_key) {
    $key_as_value = $key;
    last;
  }
}
@a = each %hash;  # reset each iterator


Smart way - create a second hash, which maps values to keys:

%values_to_keys = reverse %hash;

$key_as_value = $values_to_keys{$value_as_key};

# watch out if some keys share the same value!!


Foolproof way - create a second hash, which maps values to keys:

%values_to_keys = ();
while (($key, $value) = each %hash) {
  push @{$values_to_keys{$value}}, $key;
}

@keys_as_value = @{$values_to_keys{$value_as_key}};

# handle the problem of keys sharing the same value


-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 06 Nov 1998 09:54:25 +0800
From: Terry Gliedt <tpg@cls.uob.com.sg>
Subject: Re: ODBC Resource?
Message-Id: <364256D1.F4D27220@cls.uob.com.sg>

I'll send you directly a couple of Perl programs I've developed and use with
ODBC. I came up with these as part of my learning process with Perl ODBC and
to test that it was working. Hope you find them of use.

Geoff Caylor wrote:

> Hello,  I'm looking for any sort of resource for ODBC programming for the
> Win32 environment, and so far haven't found anything of value...
>
> Any leads are greatly appreciated!
>
> Geoff Caylor

--
================================================================
Terry Gliedt     tpg@cls.uob.com.sg    http://www.hps.com/~tpg/
United Overseas Bank               Personal Email:  tpg@hps.com




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

Date: 6 Nov 1998 04:33:27 GMT
From: pete@localhost.localdomain (Peter J. Kernan)
Subject: Re: Odd number of elements?
Message-Id: <71tu6n$6hq$1@pale-rider.INS.CWRU.Edu>

In article <36422C3E.914E8AA7@tiac.net>,
	Alex Vandiver <vandiver@tiac.net> writes:
> I'm confoogled.  Why does perl choke about "Odd number of elements in
> hash list" on the follwong lines of code?
> 
> @a = split(/[\s+=]/,$line);           # $line being "FOO=bar BAZ=zort"
> print "Array:".(scalar @a)."\n";      # Prints 4
> %h = {@a};                            # Dies
> print "Hash:".(scalar keys %h)."\n";  # Prints 0
> 
> Any extra cluefulness for the clueless wandering around out there?
> -Alex Vandiver
> 
how about?

%h = m/(\S+)\s*=\s*(\S+)/g;

(unless you want @a for something else)

-- 
open SIG, "<$ENV{HOME}/.sig"         or die       "sigless!     $!"; 
$sig = do {local $/; <SIG>};         close SIG && print<<"$sig SIG";
        Pete Kernan  CWRU Physics and Statistics Depts
        http://theory2.phys.cwru.edu/~pete
$sig SIG


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

Date: Fri, 6 Nov 1998 00:03:17 -0500
From: "Roger Kenneth Trussell" <rtrussell@hps-inc.com>
Subject: OLE and ActiveState, Why so slow?
Message-Id: <71u09n$cqg$1@supernews.com>

Hello everyone,

    I'm puzzled by this problem. It may be due to something stupid that I
did to my own computer.

    I'm trying to use ActiveState's OLE extensions to Perl for Win32. I'm
able to create the Automation object that I want, but it seems to take
forever to call the methods and the properties that I want. Is Perl for
Win32 doing something strange when it interacts with Automation objects that
make it slow sometimes?  Is there probably something stupid that was
configured incorrectly in the object?

Sincerely,
Roger Trussell





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

Date: Fri, 06 Nov 1998 05:36:43 GMT
From: bfenwick@mts.net (Brad Fenwick)
Subject: pass a file directly to stdout?
Message-Id: <364287ec.31105230@news.mts.net>

I am writing a web database. I am trying to find a way to simply pass
a file, unparsed, directly to STDOUT. Basically I want to serve up
some html pages that are outside the web root to STDOUT and hense back
to the browser. The cgi "Locate: /bla/bla.html" command is of no use
because it only works with files off of your web root. My attempts to
open the file with perl open, and then parse through the filehandle...
which normally works... seems to get caught. My assumption is that is
because perl is trying to parse the file as I read it in line by line,
and obviously running into trouble with anything that it thinks is a
perl var or escaped something.

My guess is there is a very elegantly simple way to pass a file to
stdout (without using a system command) without having to parse it
through first and print it out that way... I just can't find any clear
examples that show me that elegant way.

Thanks, 
Brad


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

Date: Thu, 5 Nov 1998 23:55:57 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: perl questions PLEASE HELP :)
Message-Id: <1di1oaf.phqm6816dzsn9N@bay1-59.quincy.ziplink.net>

jcl <jcl4sale@yahoo.com> wrote:

> Hey everyone,
>   I do not like to go to newsgroups for my programming problems
> (because i like to figure it out on my own), but this has to be done
> my tomorow afternoon, and i don't know what else to do. The program
> has to simulte the part  of a network layer and i have most of it done
> with two main problems.

Sounds like homework.

We'd like you to figure it out on your own too.

> 1) 
>   I need to search in a string for five ones, and if so replace it
> with a five ones and a zero i.e.
> 
> 11111 would become 111110
> 
> and 111111011111101110111111 would become :
> 111110101111101011101111101
> and so on,
>  i  tried using : s/11111/111110/ and with the g option, but the
> program just waits or freezes, it can't tell but ctrl+c stops it. It
> works as s/1111/11110/ and s/111111/1111101/ but not the way i need it
> to.

s/11111/111110/g should work just fine.  The problem in your script must
lie elsewhere.

> 2)
>   I also would like to know away, to thorw away the current input.
> What i mean is, i'm reading from stdio, and i sometime just wan't to
> toss the current string and read the next one, there's probably a real
> simple way to do this, but i don't know, (BTW i'm using a while to get
> data from stdio).

Surely you mean you're reading from STDIN.  If you want to go to the
next line of input, just do so.
^^^^

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 06 Nov 1998 05:20:38 GMT
From: hovi <hovi@mtco.com>
Subject: Please help on finding difference between dates.
Message-Id: <3642874E.DD2CD4@mtco.com>

I am very new at Perl so you will have to excuse me.  I have the binary
version of Perl 5004_02 and running it on Windows 95 and I do not have a
C Compiler.  I am trying to find a way to calculate the difference
between two dates.  Every example I see uses the CALC module which I
cannot use because I do not have a compiler.  Could somebody give me
some suggestions on what to do.  Please email me at hovi@mtco.com or
c_hovious@hotmail.com.

Thank You.




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

Date: Thu, 5 Nov 1998 20:32:00 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: simple scalar question
Message-Id: <03nt17.c35.ln@flash.net>

pjgeer@hotmail.com wrote:

: if ( $cond ) { ... };  #tests if $cond matches 0 or undef


   That is not how "truth" works in perl (both of those _are_
   false, but there are others too...)


   To determine true/false in Perl:

   1) if it is not a string, convert it to a string

   2) if it is the empty string or the one character string '0',
      then FALSE, else TRUE


   $cond = undef;  # converts to empty string - FALSE

   $cond = 0;      # converts to '0' - FALSE

   $cond = 0.0;    # converts to '0' - FALSE

   $cond = '0.0'   # string is not one of those two - TRUE


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 5 Nov 1998 23:55:59 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: simple scalar question
Message-Id: <1di1oof.tsyvtg1rqhomN@bay1-59.quincy.ziplink.net>

<pjgeer@hotmail.com> wrote:

> And this doesn't work:
> eval { if( $cond ) { ... } };

You don't need to eval the whole thing, just the conditional part.

if (eval $cond) { ... };

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 5 Nov 1998 21:54:02 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: system(". $file"); #odd result!
Message-Id: <qsrt17.4h5.ln@flash.net>

Navin Chander (navin@ti.com) wrote:

: Is there a way to run two commands one after another in the same sub shell using
: system


   The same way you run two commands one after another in the shell  ;-)

      system "echo 'goodbye filesystem'; rm -rf /";



[ snip a bunch of HTML crap ]


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 05 Nov 1998 17:30:52 -0800
From: Arvind Krishnaswamy <arvindk@pa.dec.com>
Subject: Using recv in Socket programming
Message-Id: <3642514C.5A62D1F7@pa.dec.com>

I want to use the recv function multiple times to get data from a socket
into a buffer. The bytes of data vary with each recv (and this is not
known). Is there any way I can use recv to do this? What is the
alternative if I cannot use recv?

If I specify a fixed number like 1000 for example, I may not get all
data if it exceeds that number. The code basically looks like

for (@querylist) {
 ....
 ....
printf SOCKET $query;
recv (SOCKET, $result, ???? , 0);
}

Thanks,

Arvind



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

Date: 05 Nov 1998 18:38:25 -0700
From: "Eric The Read" <emschwar@mail.uccs.edu>
Subject: what does split do on empty fields?
Message-Id: <xkfemrhmwha.fsf@valdemar.col.hp.com>

I know this has got to be a FAQ, but I just checked, and it doesn't seem
to be.  I tried searching DejaNews on 'split', but I got so much noise
(noise as far as solving this problem is concerned), I'm not sure how to
separate out the wheat from the chaff.

Anywho, here's my problem:

I have an ASCII file separated by | characters (don't ask me how it got
that way, it's a long and gruesome story).  Each line has up to 26
fields.  I have dates stored in format 'YYYY/MM/DD' in fields 21 and 22,
which I need to convert to "DD-MON-YYYY".

The problem is, not all lines have fields 21 and 22 defined-- they just have:

"[20 fields]|||[some more fields]" or
"[20 fields]|1998/11/05||[some more fields]" or
"[20 fields]||1998/11/05|[some more fields]"

in them.  That's fine-- if there's nothing there, I don't need to convert 
anything, so I want to skip that field.

I separate out the fields by doing

@tmp = split /\|/;

My question is, what does "split" do if the value between the split
characters is empty?  I've tried testing

if(defined $tmp[21])
if($tmp[21] ne '')

to find out if there's anything in that field, but neither of those seem
to work.

Feel free to tell me to piss off and RTFM-- but please at least let me
know which FM to R, as 'perldoc -f split' isn't particularly informative
on this topic, and neither the blue camel, nor any FAQs or web resources
I can find seem to have the answer I'm looking for.

I'm using perl 5.004_04.

-=Eric


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

Date: Thu, 5 Nov 1998 21:32:47 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: what does split do on empty fields?
Message-Id: <vkqt17.uf5.ln@flash.net>

Eric The Read (emschwar@mail.uccs.edu) wrote:

: My question is, what does "split" do if the value between the split
: characters is empty?  I've tried testing

: if(defined $tmp[21])
: if($tmp[21] ne '')

: to find out if there's anything in that field, but neither of those seem
: to work.


   That's strange. The second one should work. There is something
   else going on...


: Feel free to tell me to piss off and RTFM-- 


   WAFTS (Write A F Test Script) and see what it does:

--------------------
#!/usr/bin/perl -w

$_ = 'one|two||four|five';

foreach (split /\|/) {
   print "'$_'\n";
   print "empty string\n" if $_ eq '';
   print "not defined\n" unless defined($_);
}
--------------------

output:
'one'
'two'
''
empty string
'four'
'five'


Testing for the empty string ought to do it...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 5 Nov 1998 23:55:59 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: what does split do on empty fields?
Message-Id: <1di1ou8.h23p3y1n66vb4N@bay1-59.quincy.ziplink.net>

Eric The Read <emschwar@mail.uccs.edu> wrote:

> My question is, what does "split" do if the value between the split
> characters is empty?

Does this answer your question?

  DB<1> x split /\|/, "[20 fields]|||[some more fields]"
0  '[20 fields]'
1  ''
2  ''
3  '[some more fields]'
  DB<2> 

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4163
**************************************

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