[7122] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 747 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 19 18:08:35 1997

Date: Sat, 19 Jul 97 15:01:50 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 19 Jul 1997     Volume: 8 Number: 747

Today's topics:
     Need some help... <jlovettte@mhv.net>
     Re: Newbie confusion <westxga@ptsc.slg.eds.com>
     Re: Null file handle: Is it the angle operator's ignora (M.J.T. Guy)
     pack 'N' bug on IRIX? (5.004_01) (Honza Pazdziora)
     Parsing a list of strings (Bernard Cosell)
     Re: Parsing a list of strings (Even Holen)
     Re: Parsing a list of strings (Bill Napier)
     Re: Perl 5.004 Socket from inetd (Jose Rocha)
     Re: perl shell? <zenin@best.com>
     Perl*Unix*SUID - question (Helmut Jarausch)
     Re: process as a filehandle (Even Holen)
     References and Objects w.stanton@auckland.ac.nz
     Re: References and Objects <sfairey@adc.metrica.co.uk>
     Re: regular expressions help needed :-) (Honza Pazdziora)
     Re: some unexpected output xewj@odin.sunquest.com
     Strings <brian@shepmark.com>
     subroutine arguments question continued (Malunjkars)
     Re: subroutine arguments question continued <bkyan@mindcast.com>
     subroutine arguments <Uwe.Lammers@astro.estec.esa.nl>
     Re: subroutine arguments (Tad McClellan)
     Re: swiching dircetories <zenin@best.com>
     Re: The Shaft? <rootbeer@teleport.com>
     Tips for improving performance over NFS <sfairey@adc.metrica.co.uk>
     Re: Uploading a file without using Net::FTP <drummj@poa.mmc.org>
     Re: Using STDIN for an IF/ELSE script (Even Holen)
     What happens when.... (Dico Reyers)
     Re: Writing perl modules. (Jonathan King)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 19 Jul 1997 16:25:28 -0400
From: James Lovette <jlovettte@mhv.net>
Subject: Need some help...
Message-Id: <33D122B8.4F8D@mhv.net>

Can anybody out there write a script for me?  I want it to be one where
the visitor is given a list of choices and based on those a price is
outputted, similar to customizing a computer system online like at
http://www.vektron.com/quote/QMMS1.HTM
I would really appreciate it, I have tried to learn perl for 5 months
and it still makes no sense.  Please respond by e-mail, thank you.

James Lovette
mailto:jlovette@mhv.net


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

Date: Thu, 17 Jul 1997 11:11:29 -0400
From: Glenn West <westxga@ptsc.slg.eds.com>
Subject: Re: Newbie confusion
Message-Id: <33CE3621.2D31@ptsc.slg.eds.com>

Chuck Mattern wrote:
[Text removed]

I don't think your problem has to do with variables being unset.  Rather
it has to do with the fact that your input doesn't match the regular
expression.  The reason just typing in "shut" doesn't work is because
the pattern matching fails on the required 1 or more whitespace
characters (\s+) after the first \w+, not to mention the required 1 or
more word characters (\w+) at the end of the regular expression.  And if
you enter "shut the", the word "the" ends up as the noun since the
"other words" is optional and you still don't get what you expect.

One solution is to change .* to \w+ and the last + to *.  This would
require you to enter "shut the" in order to get the "How do I shut?"
phrase and entering "shut the door" would result in "Where is door?". 
Which is what it sounds like was intended in the first place...


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

Date: 18 Jul 1997 16:38:26 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Null file handle: Is it the angle operator's ignorance or mine?
Message-Id: <5qo662$rc5@lyra.csx.cam.ac.uk>

Ronald Fischer  <rovf@earthling.net> wrote:
>I use the following program 'cols' to compute the size of the longest
>line in a set of files:
>#!/bin/perl 
># cols [FILE...]
>$maxlen = 0;
>while (<>) {
>   (length > $maxlen) && ($maxlen = length);
>}
>print "$maxlen\n"
># end of cols
>
>This works fine as long as I do not supply a filename starting with a
>'+'. But when I write (for example)
>    cols +foo
>I get the output
>    Can't open +foo: No such file or directory
>although
>    cols ./+foo
>and
>    cols <+foo
>work as expected. It looks to me as if the '+' has a special
>significance (like turning off some options), but I don't see andy
>relationship to the <> operator.

+foo works OK for me.    Perhaps your shell is doing something with the
"+"?

>(And while we are it: Just in case someone feels urged to critize my
>program or to improve it in some way, s/he is cordially invited to do so)

Only comment is that the length will include the newline.   But perhaps
that's what you want.   And of course, you can make it a one-liner:

 perl -ne 'length>$maxlen&&($maxlen=length);END{print"$maxlen\n"}' +foo

But you probably knew that.


Mike Guy


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

Date: Fri, 18 Jul 1997 15:44:13 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: pack 'N' bug on IRIX? (5.004_01)
Message-Id: <adelton.869240653@aisa.fi.muni.cz>

Halo, I have found this strange behaviour of 5.004_01's pack on IRIX
recently. Before I send it via perlbug, could somebody with IRIX
please check if it's only my machines doing this?

#!/usr/bin/perl -w
use strict;
my $b = 5;
$a = '-43947780';
$b += $a;
print "print: $a, ", unpack('H*', pack('N', $a)), "\n";
__END__

This example gives me

print: -43947780, ffffffff

on output. Now, on Linux and Solaris, the output is (expected)

print: -43947780, fd6168fc

and I am able to get this on IRIX when I comment out the line

$b += $a;

Any ideas? Thanks.

My perl -V follows:

Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
  Platform:
    osname=irix, osvers=5, archname=IP19-irix
    uname='irix aisa 5.3 11091811 ip19 mips '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=n useperlio=define d_sfio=
  Compiler:
    cc='cc', optimize='-O2', gccversion=
    cppflags='-w -D_POSIX_SOURCE -ansiposix -D_BSD_TYPES -DLANGUAGE_C'
    ccflags ='-w -D_POSIX_SOURCE -ansiposix -D_BSD_TYPES -Olimit 3000 -DLANGUAGE_C'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=1, d_casti32=define, d_castneg=
    intsize=4, alignbytes=8, usemymalloc=n, randbits=15
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib
    libs=-lmalloc -lsun -lm -lc -lcrypt -lbsd -lPW
    libc=/usr/lib/libc.so, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
    cccdlflags='-KPIC', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Built under irix
  Compiled at Jun 30 1997 17:58:28
  @INC:
    /packages/run/perl-5.004/lib/IP19-irix/5.00401
    /packages/run/perl-5.004/lib
    /packages/run/perl-5.004/lib/site_perl/IP19-irix
    /packages/run/perl-5.004/lib/site_perl
    .


--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Fri, 18 Jul 1997 13:20:02 GMT
From: bernie@rev.net (Bernard Cosell)
Subject: Parsing a list of strings
Message-Id: <33d16c63.573984056@news.rev.net>

I need to parse ['split', actually!] a list of strings out of a
database dump.  So I have something that looks like:
   "field1", "field2", .., "fieldn"
and I can't find a non-ugly way to handle it.  I can't just split on
','s because the field strings can include commas.  The field strings
can also include ditto marks [which are doubled], and so
   ..., """", ...
is a field consisting of a single ditto-mark.  Any tricks or tips for
parsing/handling this mess?  It feels like it ought to be easy [since
that is such a simple/standard format], but everything I try is hard
and/or ugly...  [this with 5.03 on Linux] Thanks!!

  /Bernie\
-- 
Bernie Cosell                        mailto:bernie@rev.net
Roanoke Electronic Village


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

Date: 19 Jul 1997 12:09:15 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Parsing a list of strings
Message-Id: <slrn5t1bfm.7og.evenh@ra.pvv.ntnu.no>

In article <33d16c63.573984056@news.rev.net>, Bernard Cosell wrote:
>I need to parse ['split', actually!] a list of strings out of a
>database dump.  So I have something that looks like:
>   "field1", "field2", .., "fieldn"
>and I can't find a non-ugly way to handle it.  I can't just split on
>','s because the field strings can include commas.  The field strings
>can also include ditto marks [which are doubled], and so
>   ..., """", ...
>is a field consisting of a single ditto-mark.  Any tricks or tips for
>parsing/handling this mess?  It feels like it ought to be easy [since
>that is such a simple/standard format], but everything I try is hard
>and/or ugly...  [this with 5.03 on Linux] Thanks!!

Try looking into the Parse::Text module. It does a lot of these thing
without you having to reinvent the wheel... :)

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: 18 Jul 1997 13:43:19 GMT
From: napier@blue.seas.upenn.edu (Bill Napier)
Subject: Re: Parsing a list of strings
Message-Id: <5qnrtn$kil@netnews.upenn.edu>

Bernard Cosell (bernie@rev.net) wrote:
>I need to parse ['split', actually!] a list of strings out of a
>database dump.  So I have something that looks like:
>   "field1", "field2", .., "fieldn"
>and I can't find a non-ugly way to handle it.  I can't just split on
>','s because the field strings can include commas.  The field strings
>can also include ditto marks [which are doubled], and so
>   ..., """", ...
>is a field consisting of a single ditto-mark.  Any tricks or tips for
>parsing/handling this mess?  It feels like it ought to be easy [since
>that is such a simple/standard format], but everything I try is hard
>and/or ugly...  [this with 5.03 on Linux] Thanks!!

Something like this should work:

while(<STDIN>) {
    chop;
    s/(^"|"$)//g;
    for (split(/","/)) { print $_,"\n" }
}       

The keys here are first removing the leading and trailing " on each
line and then splitting on ",".

Bill Napier - CSE '98 | e-mail: napier@eniac.seas.upenn.edu
----------------------| WWW:    http://www.seas.upenn.edu/~napier
 This space for rent  | finger for more information (phone, PGP, etc.)
-----------------------------------------------------------------------
The empty word to the rescue!				-Dr. Max Mintz


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

Date: Fri, 18 Jul 1997 13:45:41 GMT
From: srocha@mail.telepac.pt (Jose Rocha)
Subject: Re: Perl 5.004 Socket from inetd
Message-Id: <33cf72ef.25637436@news.telepac.pt>

Hi Jack,

Hi have the same problem. Does anyone answer you? If yes can you help
me?

Thanks in advance.




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

Date: 18 Jul 1997 10:01:28 GMT
From: Zenin <zenin@best.com>
Subject: Re: perl shell?
Message-Id: <5qneto$j65$1@nntp2.ba.best.com>

Shimpei Yamashita <shimpei@socrates.caltech.edu> wrote:
	>snip<

ftp://ftp.cdrom.com/pub/perl/CPAN/doc/FAQs/FAQ/PerlFAQ.html#Is_there_a_Perl_shel_

-- 
-Zenin
 Quake Clan After Shock (Did you feel that?)
 The Bawdy Cast - Rocky Horror Picture Show (San Jose, CA)
 zenin@best.com


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

Date: 18 Jul 1997 08:11:14 GMT
From: jarausch@numa1.igpm.rwth-aachen.de (Helmut Jarausch)
Subject: Perl*Unix*SUID - question
Message-Id: <5qn8f2$9rc$1@news.rwth-aachen.de>

Hi,
is there a chance to use a perl script which is world executable
but not world readable?

I tried to make the script suid (yes, I do have suidperl), but the
problem seems to be that the shell cannot read the script (esp. the 1st line)
when invoked from a different user.

The only way out I currently see, is to use a 'dummy' script which
just does 'require' for a script which can only be read by the suid-user.

Thanks for any hints,
Helmut.


-- 
Helmut Jarausch
Lehrstuhl f. Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany


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

Date: 18 Jul 1997 11:51:31 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: process as a filehandle
Message-Id: <slrn5sum2k.bdm.evenh@ra.pvv.ntnu.no>

In article <33CF0CEC.344F46A2@onr.com>, Broc Stirton wrote:
>I am new to PERl, so bear with me...

I'll try... :)

>I wrote a small script which tails the syslog on my linux box.  Its
>purpose is to watch for various lines and start programs based on whats
>logged (e.g. playing music when someone telnets in, and starting my
>network monitor when my ppp link goes up). 

First of all I do feel a need to say that this is the wrong way around
of doing thing. If you want something to happen when login occurs then
you ought to change the login scripts, not tail the syslog. The sames
goes for the ppp link... 

>                                     ...  I have two problems:
>1.  When I start this script (or ANY script which opens a process as a
>filehandle), I get the following warnings:
>
>warning: setlocale(LC_CTYPE, "") failed.
>warning: LC_ALL = "(null)", LC_CTYPE = "(null)", LANG = "us",
>warning: falling back to the "C" locale.
>
>The program still runs, but what does this mean?

This means that the setup of your environment isn't correct. Try looking
into the setup of bash or whatever you use as a shell... Most probably
something within .bashrc if I'm not totally wrong...

>2.  When I run this program (it is included farther down), it works for
>the first instance logged in the syslog, but after that it doesn't
>work.  It is still running (I can see from 'ps'), but after the first
>time I start and stop my ppp it no longer starts xnet when I start up
>ppp again, or kills it when I shut it down.  

All of you calls to system will hang until they are finished with
whatever they want to do...

Look into using either system("some command &") which sends it into the
background or using fork in some way... I suggest add a trailing & to
your commands. That way the system returns rather soon to continue your
script... :)

>Thank you for your help.  If you don't mind, please cc: my mail-- my
>ISP's news server has been on the fritz lately, and I don't want to miss
>any replies.

Is done...

>P.S. I know this probably isn't very efficient- its one of my first
>attempts at PERL scripting- any improvements in this vein are welcome as
>well.

What happens if several try to log in and you already are playing
music... Just a hint...

Looking for exitcodes are always essential...

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: 17 Jul 1997 09:44:38 +1300
From: w.stanton@auckland.ac.nz
Subject: References and Objects
Message-Id: <wksoxe6821.fsf@RIDO.i-have-a-misconfigured-system-so-shoot-me>


I have a mysterious problem.  I have a work around but I cannot
understand why I have to use it.

I have the Camel book 2nd edition and I am working from the examples
in chapter 5.

I have an object that uses an anonymous array to store an array of
referrences to 2-element arrays. It is created thus...

In sub new...


sub new {
    my $class = shift; # Allows this to be subclassed see camel pg 291
    my $self = {}; # Associate spaces with evaluations
    bless $self, $class;
    $self->_initialise;
    return $self;
}
sub _initialise {
    my $self = shift;
    $self->{list} = {}; # Associates design spaces with evaluations
    # The next members are used privately
    $self->{eval_list} = [ ]; # Associates evaluations with design spaces
    $self->{totalEvals} = 0; # The total of all the evaluations
} 

The offending array is...

    $self->{eval_list} = [ ]; # Associates evaluations with design spaces
I wish to reference this array later and I expect to use the following...

    push @$self->{eval_list}, [$evaluation, $design];

But this does not compile. The error message is...

Type of arg 1 to push must be array (not associative array elem) at
 DesignSpaceList.pm line 36, near "];"

But if I say...

    my $ref = $self->{eval_list};
    push @$ref, [$evaluation, $design];

All is OK.

Obviously I have a missunderstanding of the syntax.  But what is it?  

Worik Stanton
w.stanton@auckland.ac.nz


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

Date: Fri, 18 Jul 1997 15:01:24 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: w.stanton@auckland.ac.nz
Subject: Re: References and Objects
Message-Id: <33CF7734.A018DE4C@adc.metrica.co.uk>

w.stanton@auckland.ac.nz wrote:

> I have a mysterious problem.  I have a work around but I cannot
> understand why I have to use it.

Sometimes helps you to understand things better when you find a work
around then see what should have been done. At least you have something
to work with in the meantime.

>     $self->{eval_list} = [ ]; # Associates evaluations with design
> spaces
> I wish to reference this array later and I expect to use the
> following...
>
>     push @$self->{eval_list}, [$evaluation, $design];
>

I think you need to use the following syntax:

@{$self->{eval_list}}

Hope that's right :)

Simon



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

Date: Fri, 18 Jul 1997 11:15:54 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: regular expressions help needed :-)
Message-Id: <adelton.869224554@aisa.fi.muni.cz>

the count <eglamkowski@mathematica-mpr.com> writes:

> I have some text going into an html document and I want to add
> teletype tags if the text is between brackets ([...]).
> The stuff between brackets is limited in what it can look like to
> [\w+] or [(\w+) (\w+)] or [(\w+) (\w+)(:.)?] or, optionally,
> the last two might have <i></i> tags around it:
> [(<i>)?(\w+) (\w+)(<\/i>)?] and [(<i>)?(\w+) (\w+)(:.)?(<\/i>)?]
> 
> I want to add <tt> right after the [ and </tt> right before the ]
> in all cases.  I tried:
> s/\[(<i>)?(\w+)(\s*)?(\w+)?(:.)?(<\/i>)?\]/\[<tt>$1$2$3$4$5$6<\/tt>\]/g;
> 
> But it is not adding the <tt></tt> tags as I want.
> Any help as to what I am doing wrong here? :O

Interesting. I tried

$ perl
$_ = "kjh [kj fjh] kjh";
s/\[(<i>)?(\w+)(\s*)?(\w+)?(:.)?(<\/i>)?\]/\[<tt>$1$2$3$4$5$6<\/tt>\]/g;
print "$_\n";
__END__
kjh [<tt>kj fjh</tt>] kjh

$ perl
$_ = "kjh [kj] kjh";
s/\[(<i>)?(\w+)(\s*)?(\w+)?(:.)?(<\/i>)?\]/\[<tt>$1$2$3$4$5$6<\/tt>\]/g;
print "$_\n";
__END__
kjh [<tt>kj</tt>] kjh

$ perl
$_ = "kjh [<i>sdfkjh kjh</i>] kjh";
s/\[(<i>)?(\w+)(\s*)?(\w+)?(:.)?(<\/i>)?\]/\[<tt>$1$2$3$4$5$6<\/tt>\]/g;
print "$_\n";
__END__
kjh [<tt><i>sdfkjh kjh</i></tt>] kjh

and all cases work just fine, I think. What does it mean "it is not
adding ... as I want"? How is it adding and how do you want it?

BTW, you might consider changing the Subject to

	Subject: Interesting regular expression with parentheses

the next time.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 16 Jul 1997 16:31:37 GMT
From: xewj@odin.sunquest.com
Subject: Re: some unexpected output
Message-Id: <5qit19$ol0$1@iggy.sunquest.com>

In article <33CC213D.8B8E4B43@wco.com>,
Kenneth Kin Lum  <kinlum@wco.com> wrote:
>Guess what the following give give?
>$test = "AAA BCBC AAA";
>$test =~ s/([^x])BC/$1y/g;
>print "test is $test\n";
>----
>Now, the output:
>test is AAA yBC AAA
>Is this supposed to be so, not
>test is AAA yy AAA

It's working correctly, as per regexp rules:
[^x] is matching the space before the first "BC"
The first "BC" is then used up.
"BC AAA" (the remainder) is then compared to "^[x]BC" and found not to match.



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

Date: Fri, 18 Jul 1997 13:09:48 -0500
From: "Brian Shepard" <brian@shepmark.com>
Subject: Strings
Message-Id: <33cfa1c4.0@news.total.net>

I am trying to evaluate a string that contains a variable. For example:


$lcuser = 'Frank';

$x = "search.pl?user=$lcuser";

print "x=" . $x;

I want the output to be: x=search.pl?user=Frank

I have tried using the eval($x) function, but it was returning a empty

string.



Any help is greatly appreciated, please reply to me privately and to the

group.



thanks






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

Date: 19 Jul 1997 07:01:24 GMT
From: malunjkars@aol.com (Malunjkars)
Subject: subroutine arguments question continued
Message-Id: <19970719070100.DAA09053@ladder02.news.aol.com>

>From: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
>Date: Fri, 18 Jul 1997 13:14:19 +0200
>Message-ID: <33CF500B.1FD1@astro.estec.esa.nl>
>
>Hi,
>
>a newbie question for you experts out there. I want to have a
>subroutine which receives two arguments (the last of which is optional),
>a list of strings and one additional string:




I have  had this question for ages but I generally get around this
problem by following workarounds:

1.Pass  list as the last argument like &f($arg1,@arg2)
2. Above solution has the limitation that you can only pass one list.
   This can be overcome by passing reference to a list like

  sub f{
    my ($r_list,$arg2)=@_;
   
   print "list=@$r_list\n";
   print ",arg2=$arg2\n";
}

 &f(['a','b'],'c');

3. According to the programming perl5 book pages 118-121,a more elegent
way would be to  use a prototype with escaped @. This
is supposed to tell the perl not to eat up the rest of the input 
arguments for the list. Sounds good,but it doesn't work for me.
I have perl 5.003.  

Am I missing something here? Please let me know if this works for
anyone.

Here's the sample code:

   sub f(\@$)
 {
      my (@list,$arg2)=@_;
     print "list=@list\n";
    print "arg2=$arg2\n";
 }

&f(('a','b'),'c');


Thanks in advance for your help,
Sanjay Malunjkar



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

Date: Sat, 19 Jul 1997 00:39:26 -0700
From: Benjamin Kyan <bkyan@mindcast.com>
To: Malunjkars <malunjkars@aol.com>
Subject: Re: subroutine arguments question continued
Message-Id: <33D06F2E.BC893ADB@mindcast.com>

Malunjkars wrote:
> 
>Please let me know if this works for anyone.
> 
> Here's the sample code:
> 
>    sub f(\@$)
>  {
>       my (@list,$arg2)=@_;
>      print "list=@list\n";
>     print "arg2=$arg2\n";
>  }
> 
> &f(('a','b'),'c');
  ^
  I don't think prototypes work with the ampersand...

  Try:
        f ('a','b'), 'c';

-- 

Best Regards,
Benjamin Kyan
bkyan@mindcast.com

==========================  ========================  ==============
Clickstream Communications  9101 W. Sahara, #105-183  T 404.685.0852
(website) www.mindcast.com  Las Vegas, Nevada  89117  F 404.685.0853
==========================  ========================  ==============


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

Date: Fri, 18 Jul 1997 13:14:19 +0200
From: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
Subject: subroutine arguments
Message-Id: <33CF500B.1FD1@astro.estec.esa.nl>

Hi,

a newbie question for you experts out there. I want to have a
subroutine which receives two arguments (the last of which is optional),
a list of strings and one additional string:

sub f {
    (@list, $string) = @_;

     print "1: @list\n";
     print "2: $string\n";
}

When I call:

&f(('a', 'b'), 'c')

I expect to see:

1: a b
2: c

but I get:

1: a b c
2:

Suggestions? (as said, $string should be optional, i.e.,
&f(('a', 'b')) -> 1: a b 2:    )


Cheers
Uwe (ulammers@astro.estec.esa.nl)


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

Date: Fri, 18 Jul 1997 07:26:52 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: subroutine arguments
Message-Id: <cennq5.5d8.ln@localhost>

Uwe Lammers (Uwe.Lammers@astro.estec.esa.nl) wrote:
: Hi,

Hi.

: a newbie question for you experts out there. I want to have a
: subroutine which receives two arguments (the last of which is optional),
: a list of strings and one additional string:

: sub f {
:     (@list, $string) = @_;

:      print "1: @list\n";
:      print "2: $string\n";
: }

: When I call:

: &f(('a', 'b'), 'c')

: I expect to see:

: 1: a b
: 2: c

: but I get:

: 1: a b c
: 2:


You get that because @list slurps in all of the values.

sub f { my($string, @list)...

is the usual way, but that won't work in this case because $string
is optional (you probably want a my() in your sub though).


: Suggestions? (as said, $string should be optional, i.e.,
: &f(('a', 'b')) -> 1: a b 2:    )


I would suggest seeing what the Perl FAQ says about this very question ;-)


-------------------------
=head2 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?

With the exception of regexps, you need to pass references to these
objects.  See L<perlsub/"Pass by Reference"> for this particular
question, and L<perlref> for information on references.
-------------------------

: Cheers


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 18 Jul 1997 16:59:48 GMT
From: Zenin <zenin@best.com>
Subject: Re: swiching dircetories
Message-Id: <5qo7e4$q76$2@nntp2.ba.best.com>

alan rogers xr/be <etlanrs@etlxdmx.ericsson.se> wrote:
> I was wondering if anyone can point me in the right direction.
> I am using perl with clearcase and it uses the lost+found directory to place all the files that you have removed in there.
> What I have done is to look at the lost+found directory and look at the directory if it equals zero then the program ends,if it does not equal zero then my program will remove all the files from lost+found.
> The problem is I can do this for one directory but I was wondering if there is a way of searching another directory for lost+found if it equals zero then it searches the next directory (if it does not equal zero then it will do my program) until it searches all the directories (at the moment they are ten but this number will probably increase) and when all the lost+found directories equals zero then the program ends.

	perldoc File::Find

-- 
-Zenin
 Quake Clan After Shock (Did you feel that?)
 The Bawdy Cast - Rocky Horror Picture Show (San Jose, CA)
 zenin@best.com


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

Date: Fri, 18 Jul 1997 17:58:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: srsutton@ibm.net
Subject: Re: The Shaft?
Message-Id: <Pine.GSO.3.96.970718174534.17347H-100000@kelly.teleport.com>

On Fri, 18 Jul 1997, Shawn R. Sutton wrote:

> We have a web page (www.doughertyassoc.com) that is HTML exclusively. 
> Our ISP has told us that new changes we wish to make to our web page
> requires porting to Perl. We have no problem with this but believe the
> time factors involved are a bit excessive ($125 an hour) for some of the
> tasks.

I wouldn't do it myself for that amount, but I'm sure that you can find
somebody who would. :-) 

> I was hoping that some experts could give me feedback on the
> general changes. Such as porting our page will take 6 hours. 

I can't say. It's like saying how long it would take to read a book. 
"Porting a page to perl" is a vague concept. What really needs doing? If
you merely need a script to print out the existing text, five minutes. If
you need a script to write the text using sophisticated AI, twenty years. 
Your requirements are probably somewhere in between. :-) 

> Adding a "new" tag to inputed jobs 2 more hours. 

I don't know what that means. But maybe it takes two hours. :-)

> A simple back button at the bottom of each page another hour.

Naw. You can't make a back button that really works. Putting "use the back
function of your browser to go back" in all of the appropriate places:
about eight pages per hour. (If the pages are in a simple, standard
format, ten minutes total, even if there are ninety-nine of them.) 

> And a CGI form mailer (which I'm told is free at some sites) is 5 more
> hours.

If you have to design a form, that could take some time. Five hours,
maybe. If the form is already made, this could take less. 

> Am I getting the straight deal, or the shaft? 

Maybe. :-)

Write up some detailed specs, telling exactly what you need done. Then,
any good programmer should be able to give you a bid. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 18 Jul 1997 16:29:03 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
Subject: Tips for improving performance over NFS
Message-Id: <33CF8BBE.60254D62@adc.metrica.co.uk>

Hi,

I have a smallish script which processes directory trees for file name
and inode information. The files in question are on an NFS. I noticed
the difference in running the script locally and from a network machine
and I was wonderering if there are any tricks/tips on improving the
speed of scripts processing NFS files.

Any advice would be greatly appreciated.

Simon



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

Date: 18 Jul 1997 15:48:43 GMT
From: "Jeffrey R. Drumm" <drummj@poa.mmc.org>
Subject: Re: Uploading a file without using Net::FTP
Message-Id: <01bc9392$0180fc70$111e71c6@ohmigod>

What makes you think you have to do *anonymous* FTP with Net::FTP? That
restriction would severely limit its usefulness . . .

#!/usr/bin/perl

use Net::FTP;

$ftp = Net::FTP->new("hostname");
$ftp->login("name","password");
$ftp->cwd("/directory");
$ftp->get("filename");
$ftp->quit;

Note that you would probably want to check for return status on all the
above methods . . . I merely (mostly) lifted the example from the
documentation. Note the $ftp->login() method; it takes *any* name and
password as an argument  . . . you merely need to supply valid ones for the
system in question.

-- 

 - Jeffrey R. Drumm - Systems Integration Specialist
   Maine Medical Center - IS Department
   420 Cumberland Ave - Portland ME 04101
   Voice: 207-871-2150 - FAX: 207-871-6440
   drummj@mail.mmc.org

Euan Forrester <deforres@acs.ucalgary.ca> wrote in article
<5qm15q$juq@ds2.acs.ucalgary.ca>...
> I'm writing a Perl script that needs to send a data file it creates to
the
> user's computer, and my ftp server doesn't support anonymous ftp logins
> ("they're for clients only") so I can't just use Net::FTP to send the
file
> over. I've tried the following solutions, neither of which work as well
as
> I need:
> 
> 1. 
> 
> print "Content-type: application/octet-stream\n\n";
> open(DATAFILE, $path);
> while (<DATAFILE>) {
>   print;
> }
> 
> This sends the file okay, but the default name is the name of my Perl
script
> rather than the name of the data file I read from. According to the MIME
> document I read, a way for a suggested filename for data sent as
> application/octet-stream was suggested but not implemented in the current

> MIME specification. Also, I can't find a way to send the file's size to
> the user's browser so that they will know how long the download will take
> (the files can get large)
> 
> 2. 
> 
> print "Content-type: text/html\n\n";
> print qq!<META HTTP-EQUIV="refresh" CONTENT="0; url=http://myfile.dat">!;
> 
> My system administrator was kind enough to do something that made it so
> files with the .dat extention weren't treated as text, but were
> rather saved on the user's computer. This has neither of the above two
> problems, but it leaves the user on a blank screen after the download,
> which doesn't look very professional.
> 
> Is there a way that I can fix either of these two methods so that they
> work properly, or is there a third (or fourth) method I can use that I
> havn't thought of? Thanks in advance for your help.
> 
> 


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

Date: 18 Jul 1997 12:04:23 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Using STDIN for an IF/ELSE script
Message-Id: <slrn5sumqo.bdm.evenh@ra.pvv.ntnu.no>

In article <5ql2go$h@winter.news.erols.com>, Brad Nelson wrote:
>I'm trying to have a perl script call one of two other scripts based on a
>STDIN to a question.  The STDIN has to equal a regular expression as below.
>(This is on a HPUX 10.x unix system).
>
>REGEXP format is (ALPHA)(ALPHA)-##-#### or (ALPHA)#-##-####, using # for
>numbers.  Example: AA-00-1111 or A0-00-1111.

Try using `unpack` instead of regexps it might do the trick for you...

>    I can't figure out how to have perl "cd" to a lower directory, pass the
>STDIN/variable to
> a ksh/sed/awk script and run it.

Have you tried doing 
   cd $dirname;
I guess not, then you wouldn't have asked the question... :)

>    I have the ksh/sed/awk script returning a result file and that's where
>I want the process to end.

Then you _might_ want to use exec or some of its variant to end the perl
script as you start the next script...

>    Specifically:
>
>#!/users/bin/perl
>print "What data do you want to search the file on?  \n"
>chop($data=<STDIN>);
>
># MY PSEUDOPERL BELOW:
>if ($data eq /[A-Za-z][A-Za-z]\-[0-9]\{2\}\-[0-9]\{4\}/ || $data eq
>/[A-Za-z][0-9]\-[0-9]\{2\}\-[0-9]\{4\}/)

First of all lookup the difference of 'eq' and '=~'... 'eq' means that
the strings has to match 'literally' not by and regexps... So exchanging
it for '=~' will do quite a lot...

Second do try the unpack function.

Third suggestion is to lookup the documenation on parentheses and what
theyt mean within a regexp. They might come in handy... :)
 
>Please give me a direction.  I've searched the O'Reilly "Learning Perl"
>and "Programing Perl".  But it seems I don't yet know enough to be sure
>what Perl structure/function I'm looking for.

Hope this helps and gives you some direction on where to look for
information...

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: Sat, 19 Jul 1997 15:29:21 GMT
From: dico@peionline.com (Dico Reyers)
Subject: What happens when....
Message-Id: <33d0dd01.7641992@news.upei.ca>

What happens when two or more people try to write to a file that is
already open (ie, another person is already writing to it?).  Is there
a way to stop this from happening?

Thanks,

dico@peionline.com


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

Date: 18 Jul 1997 16:53:28 GMT
From: king@cogsci.ucsd.edu (Jonathan King)
Subject: Re: Writing perl modules.
Message-Id: <5qo728$ff5$1@news1.ucsd.edu>

In article <Pine.SUN.3.93.970716200716.6318E-100000@vidya> 
Pawan Agnihotri <pxa7@cac.psu.edu> writes:
>
>I need to write a perl extension module calling a 'C' function with a
>complex data type as an argument and getting the 'C' function to fill in
>the data type.
>
>The C code would look as follows.

[boring C code deleted]

>I have read the perlxs, perlxstut and
>perlguts man pages. I have written the code but when I call the
>function from within the perl script I get errors like
>bash-2.00$ ./PINFO.pl
>info is not a reference at ./PINFO.pl line 7.

If this isn't working yet, and the perlxs stuff is making you bleed
from your ears, you might take a look at SWIG:

 http://www.cs.utah.edu/~beazley/SWIG

SWIG will wrap your c-code for you and help you generate everything
you need to use your code from Perl.  Or some of those other
languages you may have heard about.  Seriously, it's pretty
impressive, and probably works best for the most boring code, so
you really don't have to know much at all about perlguts to get your
stuff up and running at least.

Hope this helps.

jking


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 747
*************************************

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