[6946] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 571 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 4 18:12:36 1997

Date: Wed, 4 Jun 97 15:00:43 -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           Wed, 4 Jun 1997     Volume: 8 Number: 571

Today's topics:
     Re: Atomic file create or fail if already existing (Chipmunk)
     Re: Atomic file create or fail if already existing (Leonard Megliola)
     Re: Compatibility Issues between Perl and Oracle (Michael Swertfager)
     csh.whynot, where? (Darwin O.V. Alonso)
     Re: csh.whynot, where? <rra@stanford.edu>
     Re: data structure question (Chipmunk)
     File Descriptor Memory Leak <sarah@ecl.wustl.edu>
     Re: Having problems producing an adequate s/// subst. <rra@stanford.edu>
     Re: Help for "date" (Michael James Braunstein)
     Re: Isdigit(), isalpha()  in Perl <Rosie@dozyrosy.demon.co.uk>
     Re: NcFTP, Perl, CGI - Permission Denied <root@nwdtc.com>
     Re: newbie question2 (Chipmunk)
     perl - NT and blat command line switches <jeb@wm0.lanl.gov>
     Re: perl - NT and blat command line switches (Nathan V. Patwardhan)
     pipes,x11,shell? (Darwin O.V. Alonso)
     replacing spaces with underscores <mferrell@planeteers.com>
     Re: replacing spaces with underscores (Michael James Braunstein)
     Re: Returning a filehandle from a module <rra@stanford.edu>
     select and multiple forking <HuuDa.Tran@risq.qc.ca>
     Re: Shell to Perl.... (Dave Cross)
     Re: simple question about running system programs from  (Chipmunk)
     Re: simple question about running system programs from  (Tad McClellan)
     Simple Question <mferrell@planeteers.com>
     Re: Simple Question (Nathan V. Patwardhan)
     Re: String Compare Problem (Chipmunk)
     Re: Telnet (Nathan V. Patwardhan)
     Re: Using Variables from shell <rra@stanford.edu>
     Re: why won't 'print <<end_print...end_print' work? (Chipmunk)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 4 Jun 1997 20:53:38 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Atomic file create or fail if already existing
Message-Id: <5n4kki$flt$1@dartvax.dartmouth.edu>

In article <5n452d$gl8@news.service.uci.edu>
lmegliol@inertia.acs.uci.edu (Leonard Megliola) writes:

> I need an atomic operation which will create a new file if it
> doesn't exists, but fail if the file already does exist.  The goal
> is to create unique (random) filenames, and (even though it is
> unlikely given my method of generating the filenames) I would like
> to avoid any race conditions.  I've thought about different
> variations on sysopen and open, but I don't think it is possible.

do {
  open(FILE, ">$filename") || die "Unable to create $filename: $!";
} unless -e $filename;

-e returns true if the file exists, false otherwise.

Chipmunk


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

Date: 4 Jun 1997 21:37:48 GMT
From: lmegliol@inertia.acs.uci.edu (Leonard Megliola)
Subject: Re: Atomic file create or fail if already existing
Message-Id: <5n4n7c$rl3@news.service.uci.edu>

In article <5n4kki$flt$1@dartvax.dartmouth.edu>,
Chipmunk <Ronald.J.Kimball@dartmouth.edu> wrote:
>In article <5n452d$gl8@news.service.uci.edu>
>lmegliol@inertia.acs.uci.edu (Leonard Megliola) writes:
>
>> I need an atomic operation which will create a new file if it
>> doesn't exists, but fail if the file already does exist.  The goal
>> is to create unique (random) filenames, and (even though it is
>> unlikely given my method of generating the filenames) I would like
>> to avoid any race conditions.  I've thought about different
>> variations on sysopen and open, but I don't think it is possible.
>
>do {
>  open(FILE, ">$filename") || die "Unable to create $filename: $!";
>} unless -e $filename;
>
>-e returns true if the file exists, false otherwise.
>
>Chipmunk

Thanks, I already know how to do that though.  I'm wondering if
there is an atomic version of those same actions (Unless that is
some special incantation for making the operation atomic).

My (probably unnecessary) worry is that one process of this program
will create a file with the same name in between the points where
another program checks for the existence of the same file and tries
to create it itself.  I don't think it is possible, but that's why
I'm asking.

Given that my filenames are randomly generated, maybe this is
something that I shouldn't worry about.  But it will bug me in the
back of my mind.

Thanks,

Leonard.



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

Date: Tue, 03 Jun 1997 19:12:54 GMT
From: mswertfa@cisco.com (Michael Swertfager)
Subject: Re: Compatibility Issues between Perl and Oracle
Message-Id: <5n1q2c$poe$1@news-sj-3.cisco.com>

Not trying to start rumors...
Just concerned about compatibility from what I heard...want to clarify
if this is as fact or rumor.

If anyone has heard or experienced anything about this, please email
me with what you know. I will soon be making requests from Perl5 to an
Oracle database and want to make sure I am using the correct versions
and patches if any.

-Michael

groenvel@cse.psu.edu (John D Groenveld) wrote:

>In article <5mmvs7$q25$1@news-sj-2.cisco.com>,
>Michael Swertfager <mswertfa@cisco.com> wrote:
>>I have heard rumors about compatiblity issues between Perl and Oracle.

>Rumor monger! Please clarify you question. If you are asking if you can
>access your Oracle database from a Perl script, then the answer is yes,
>see the Module List. In fact, Oracle ships perl and the appropriate modules
>with its Webserver 3.0.

>John
>groenvel@cse.psu.edu




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

Date: 4 Jun 1997 20:15:46 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: csh.whynot, where?
Message-Id: <5n4idi$13ik@nntp6.u.washington.edu>
Keywords: csh.whynot, where

perl FAQ #1 makes a reference a file csh.whynot at convex.com.
This is in an explanation as to why perl:system doesn't use csh.
I can't find that file at convex.com, does anyone out there
have it?

Thanks,
Darwin


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

Date: 04 Jun 1997 14:34:48 -0700
From: Russ Allbery <rra@stanford.edu>
To: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: Re: csh.whynot, where?
Message-Id: <m3n2p6carr.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

Darwin O V Alonso <dalonso@u.washington.edu> writes:

> perl FAQ #1 makes a reference a file csh.whynot at convex.com.  This is
> in an explanation as to why perl:system doesn't use csh.  I can't find
> that file at convex.com, does anyone out there have it?

<URL:ftp://ftp.perl.com/pub/csh/info/csh.whynot.gz>

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 4 Jun 1997 19:03:12 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: data structure question
Message-Id: <5n4e5g$62s$4@dartvax.dartmouth.edu>

In article <i0v1n5.skc.ln@localhost>
tadmc@flash.net (Tad McClellan) writes:

> : > while ($quote=<QUOTES>){
> 
> : This will end prematurely if a line in the file evaluates to false
> : (such as "0\n");
>    ^^^^^^^^^^^^^
> 
> But that is not false. 

Okay, okay, some other line in the file that evaluates to false then. 
:-)

Chipmunk


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

Date: Wed, 4 Jun 1997 15:15:52 -0500
From: Sarah Burcham <sarah@ecl.wustl.edu>
Subject: File Descriptor Memory Leak
Message-Id: <Pine.SOL.3.95.970604145336.7514C-100000@joplin.ecl.wustl.edu>

The following section of code leaks memory at roughly 3/4 of a meg per
1000 file descriptors on a sparc 4 running Solaris 2.5.1. 

I'm assuming that since file descriptors are local, the memory associated
with the file descriptors below is not going away.  Is this supposed to be
a feature or a bug?  Regardless, I guess I have to admit it was fun seeing
this execute to a resident memory size of 48M... more than that, I would
have had no swap left.  Not a good thing.

my $fh_count = 200; # something arbitrary, probably not already in use
while (1) {
    {
	# This was mainly for the benefit of proving to myself that
	# $fh was definitely going out of scope

	my $fh = $fh_count++;
	open($fh, ">/dev/null") or die "Cannot open filehandle $fh: $!";
	close($fh) or die "Cannot close filehandle $fh: $!\n";
	undef $fh;
    }
	# print number that have been opened and closed every 1000
	if (($fh_count % 1000) == 0) { print "$fh_count\n";}
}

// Sarah Elizabeth Burcham
// Engineering Computer Laboratories
// sarah@ecl.wustl.edu



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

Date: 04 Jun 1997 14:27:54 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Having problems producing an adequate s/// subst.
Message-Id: <m3zpt6cb39.fsf@windlord.Stanford.EDU>

Dan Hamilton [munged address] writes:

> The problem is conceptually simple:  Replace all spaces contained in
> quotes with a placeholder.

Well, do you allow escaping of quotes?  In other words, do you have
anything like this:

        "this is \"all\" one term"

If you don't, this is fairly easy.  If you do, the following may not
work.

sub nospaces { my $string = shift; $string =~ tr/ /\001/; $string }
$term =~ s%\"                   # Find the opening quote of a term.
             ([^\"]*)           #   Grab the entire term.
           \"                   # Find the closing quote.
          %                     # Replace the term with...
            nospaces ($1)       #   ..the term with spaces => ^A
          %xeg;                 # Change all of them.

Note that this also strips off the quotes; if you don't want that, just
modify the nospaces sub to add a " to the beginning and end of the
returned string or put the \"s inside the parens.

If you do allow escaping of quotes, the difference is that you'll probably
need to use something like (?:^|[^\\\"](?:\\\\)+\") as the marker for the
beginning of a quoted string and ((?:[^\\\"]|\\.)*) as the regex to pick
up the quoted string.  Note that these are untested.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 4 Jun 1997 20:11:12 GMT
From: mjb1@alpha3.csd.uwm.edu (Michael James Braunstein)
Subject: Re: Help for "date"
Message-Id: <5n4i50$lmd@uwm.edu>

Jun Zhuang wrote:
: Under UNIX prompt, enter "date" will get : Mon Jun 2 13:45:34 CDT 1997
: Is there a similar function in PERL? What if I only want digits of the
: date? i.e. I want 970602 instead of Jun 2 1997?
: Any help will be appreciated.
: 

there's a module for this kind of stuff, it's called DateManip, (Manip.pm)
it works great for date manipulation and has a function that works like the
unix "date" command:  

	$today = &ParseDate("today");  # returns  yyyymmdd:hh:mm:ss
	$format = &UnixDate($today, "%m/%d/%y"); # second arg. works like 
	                                         # unix 'date'. returns mm/dd/yy
	there's lots of other stuff too...read the pod in the mod...
-- 
 M  i  c  h  a  e  l    J  a  m  e  s    B  r  a  u  n  s  t  e  i  n
               I&MT UNIX and Micro-Computer consultant
    mjb1@csd.uwm.edu | mjb1@execpc.com | http://www.uwm.edu/~mjb1


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

Date: Wed, 4 Jun 1997 20:56:46 +0100
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: Isdigit(), isalpha()  in Perl
Message-Id: <KP7CHHA+hclzEw8K@dozyrosy.demon.co.uk>

In article <5mvtnr$n12$2@info.uah.edu>, Greg Bacon <gbacon@cs.uah.edu>
writes
>[Posted and mailed]
>
>In article <5mvmv6$ali@nyx10.cs.du.edu>,
>       kschwab@nyx10.cs.du.edu (Kerry Schwab) writes:
>: sub isalpha {
>:   my($string)=shift;
>:   $string=~/^[a-zA-Z]+$/;
>: }
>
>That's not necessarily completely correct, depending on locale.  Let your
>libc decide what is alphabetic like this:
>
>    sub isalpha {
>        my $str = shift;
>
>        $str =~ /^[^\W\d_]+$/;
>    }

Please could you clarify? This way allows accented letters etc?

Also is there a difference between perl 4 and 5 regarding what \W
includes/excludes?  In Learning Perl \W is defined as matching [^a-zA-
Z0-9_0] which does not allow for the exclusion of other keyboard
characters( # % ! etc); 2nd ed Programming Perl just says it matches a
nonword character. 

Thanks,

Rosemary
Who was just about to post a request on 'how do I do...' when this
thread appeared :-)
-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


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

Date: Wed, 04 Jun 1997 14:25:49 -0700
From: Alan Olsen <root@nwdtc.com>
Subject: Re: NcFTP, Perl, CGI - Permission Denied
Message-Id: <3395DD5D.DB0@nwdtc.com>

Tom Phoenix wrote:
> 
> On 28 May 1997, Dwayne Kruk wrote:
> 
> > When I execute ncftp in one of my lines of code, I'm getting permission
> > denied errors.
> 
> Do you mean that your script doesn't have permission to run ncftp, or that
> it runs but gets a "permission denied" error from the remote site?

Will ncftp contact that site outside of the script?

If not, one thing that you might want to check is if the site that is
being contacted requires reverse DNS and/or identd available.  A number
of sites have gone to this after having difficulty with crackers
attacking their sites.

> 
> And did you know that there is a module to do FTP from within Perl? It's
> called Net::FTP, if my memory is correct. Hope this helps!

Any idea why the CPAN module calls ncftp instead of Net::FTP?


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

Date: 4 Jun 1997 19:00:35 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: newbie question2
Message-Id: <5n4e0j$62s$3@dartvax.dartmouth.edu>

In article <3395E6B3.68A0@wkb.be>
steven depuydt <steven.depuydt@wkb.be> writes:

> open (SM,"test.txt");
>         while(<SM>) {
>                 if (/picture ([0-9]{1,8})\.wmf/) {
>                  s/$1\.wmf/nice.gif/g;
>                 }
>         }
> This piece of code doesn't work.
> I want to reuse the digits ([0-9]{1,8}) in my replecement rule.
> Is there a way to do this?

Your code will change all occurences of a single filename.  If the
first matched file in the string is 'picture 1234.wmf', *only* 'picture
1234.wmf' will be changed by the substitution.

>From man perlre:
  Note that a backreference matches whatever actually
  matched the subpattern in the string being examined, not the rules
for
  that subpattern.  Therefore, (0|0x)\d*\s\1\d* will match "0x1234
  0x4321",but not "0x1234 01234", since subpattern 1 actually matched
  "0x", even though the rule 0|0x could potentially match the leading 0
in
  the second number.

Thus, $1 matches the specific filename, rather than the rule which
matched that filename.

I assume you want to change all matching filenames to nice.gif.  You
don't even need to bother with the if test.

open (SM,"test.txt") || die "Unable to open test.txt: $!";
while(<SM>) {
  s/picture ([0-9]{1,8})\.wmf/nice.gif/g;
}

Chipmunk


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

Date: 4 Jun 1997 20:19:51 GMT
From: "Jeb" <jeb@wm0.lanl.gov>
Subject: perl - NT and blat command line switches
Message-Id: <01bc7124$6fc564e0$334fa580@p967651>

wrote script to send mail using blat
it wouldn't send anything until I removed
the -s "subject" from blat call
anyone else having this problem??
Thanks 
John


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

Date: 4 Jun 1997 21:19:57 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: perl - NT and blat command line switches
Message-Id: <5n4m5t$5t2@fridge-nf0.shore.net>

Jeb (jeb@wm0.lanl.gov) wrote:
: wrote script to send mail using blat
: it wouldn't send anything until I removed
: the -s "subject" from blat call

I presume you're using a filehandle, so you probably haven't escaped
the quotes, so:

open(BLAT, "|whatever -s \"subject\" etc etc") or die("error: $!");

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 4 Jun 1997 21:33:48 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: pipes,x11,shell?
Message-Id: <5n4mvs$13tc@nntp6.u.washington.edu>
Keywords: pipes,x11,shell?


I want to use a perl script to invoke a program on a remote host
to open an xwidow (a graph) on the local host.

>From the csh, I type:

 csh_prompt > rsh somehost /usr/local/bin/gnuplot -display mylocalhost:0
  plot 'plotfile.plt'
  quit
 csh_prompt >

I get a X11 window plotting plotfile.plt . However, I want to automate
this and add features. So, I write the following perl script:

  #!/usr/local/bin/perl -w
  open PIPE, '| rsh somehost /usr/local/bin/gnuplot -display mylocalhost:0' or die;
  print PIPE "plot \'a.plt\'\n";
  print PIPE "set output \'tmp.ps\'\n";
  print PIPE "set terminal postscript\n";
  print PIPE "plot \'a.plt\'\n";
  
No xwindow (I try the close command, too),
but it does create the postscript file in my home directory.
I then try :

  #!/usr/local/bin/perl -w
  open PIPE, '| rsh somehost /usr/local/bin/gnuplot -display mylocalhost:0' or die;
  print PIPE  <<EOF
  plot 'a.plt'
  EOF

Again, nothing happens, and I try:

  #!/usr/local/bin/perl -w
  system(' rsh somehost /usr/local/bin/gnuplot -display mylocalhost:0');
  
That pops me into the program but doesn't give remote:gnuplot any instructions.
I want the perl script to enter the instructions. 
Please, I would appreciate any advice on how to do this (general or specific)?

Thanks,
Darwin


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

Date: Wed, 4 Jun 1997 15:16:50 -0500
From: "Matt Ferrell" <mferrell@planeteers.com>
Subject: replacing spaces with underscores
Message-Id: <3395ccc2.0@news.cias.net>

Howdy, sorry about the simplicity of this question but I have a simple
perl
script that I need to hack some to simply replace the spaces in one of my
variables with underscores

I have a variable that gets assigned

$subject = ARGV[0];

and subject can be ( This is a test Subject )

Now I want to set $subject equal to ( This_is_a_test_Subject )

I'm really in a bind here so any help would be greatly appreciated, Thanks
in advance.

Matt Ferrell
mferrell@planeteers.com
972-713-2611






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

Date: 4 Jun 1997 20:58:45 GMT
From: mjb1@alpha3.csd.uwm.edu (Michael James Braunstein)
Subject: Re: replacing spaces with underscores
Message-Id: <5n4ku5$lmd@uwm.edu>

Matt Ferrell wrote:
: Howdy, sorry about the simplicity of this question but I have a simple
: perl
: script that I need to hack some to simply replace the spaces in one of my
: variables with underscores
: 
: I have a variable that gets assigned
: 
: $subject = ARGV[0];
: 
: and subject can be ( This is a test Subject )
: 
: Now I want to set $subject equal to ( This_is_a_test_Subject )
: 
: I'm really in a bind here so any help would be greatly appreciated, Thanks
: in advance.
: 

#!/usr/local/bin/perl -w
$subject = $ARGV[0];
$subject =~ tr/ /_/; # man perlop, and search for tr///

-- 
 M  i  c  h  a  e  l    J  a  m  e  s    B  r  a  u  n  s  t  e  i  n
               I&MT UNIX and Micro-Computer consultant
    mjb1@csd.uwm.edu | mjb1@execpc.com | http://www.uwm.edu/~mjb1


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

Date: 04 Jun 1997 14:33:06 -0700
From: Russ Allbery <rra@stanford.edu>
To: drheeder@bcs.co.za (Dirk Rheeder)
Subject: Re: Returning a filehandle from a module
Message-Id: <m3raeicaul.fsf@windlord.Stanford.EDU>

[ Posted and mailed.  comp.lang.perl no longer really exists. ]

In comp.lang.perl.misc, Dirk Rheeder <drheeder@bcs.co.za> writes:

> I'm trying to write my own module to handle some basic file functions,
> like locking etc.

> My problem is trying to return a filehandle from the module, or to send
> it one to return for me.  Is it possible to do this?

Sure.

> ie. I would like to use something like

> 	$filehandle = &mymod->fopen("file.dat");

> And then be able to read the file in the calling program something like

> 	$first = <$filehandle>;

use FileHandle;
sub fopen {
    my ($self, $filename) = @_;
    my $filehandle = new FileHandle $filename;

    # Do any additional processing that you want to here, using
    # $filehandle just as you'd use any file handle.

    return $filehandle;
}

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Wed, 04 Jun 1997 17:17:13 -0400
From: Huu Da TRAN <HuuDa.Tran@risq.qc.ca>
Subject: select and multiple forking
Message-Id: <3395DB59.6448FA7C@risq.qc.ca>

Hi,

I'm trying to use the 4 element select() function from perl.

Say I need to fork X children and I need the parent to be
able to read the children output.

I started with:

________________
for ($i=0; $i <=$x; $i++) {
  $rh="Reader_$i";
  $wh="Writer_$i";
  pipe($rh, $wh);

  FORK: {
    if ($pid = fork) {
      # Parent;
      push(@pids, $pid);
    } elsif (defined $pid) {
      print "$$\n";
    } elsif ($! =~ /No more process/) {
      print STDOUT "Redoing Fork\n";
      redo FORK;
    } else {
      die "Can't fork: $!\n";
    }
  }

  for ($j=0; $j<$i; $j++) {
    waitpid($pids[$j], 1);
  }
}

My question is, how can I use the 4-element select() to
send to the parent all child PID to be add, for example.

I have read the manpages (perlfunc, perlipc, etc.), surf
dejanews, but I just don't understand how to properly use the
	select($rin, $win, $ein, $time);

Can someone point me to the right direction to where to
insert the multiple ReadHandler?

Where would I put:
	# fhbits() as defined in Camel
	$rin = fhbits(@my_list_of_rh);

and how does the parent read different child input?



Thanks a lot,

__________________________________________________________________________
   TRAN, Huu Da                                   HuuDa.Tran@risq.qc.ca
   Iquipe NTIC                             RISQ, une division du CRIM


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

Date: Tue, 3 Jun 1997 15:56:36 GMT
From: Dave.Cross@gb.swissbank.com (Dave Cross)
Subject: Re: Shell to Perl....
Message-Id: <DAVE.CROSS.97Jun3165636@ln4d110swk.gb.swissbank.com>

In article <EB21FL.BH0.0.bloor@torfree.net> ce940@torfree.net (Michael Lauzon) writes:
 
> The following script was written for Shell, if anyone knows how to change 
> it from a Shell script to a Perl script...it would be very helpful.  And, 
> if you do change it into a Perl script; please email it to me at the 
> following email address:  ce940@torfree.net
> 
> Here is the Shell script, that needs to be changed into a Perl 
> script...with a way to send the email anonymously (sp?) and through a 
> STMP server of your choice:
>

[script snipped]

Michael,

This looks very much like a mail bomb program to me. Why would I want to
help you develop something like that?

Dave... .. .
-- 
Opinions are mine, not the company's - hell I don't think the
company even knows who I am.

Dave.Cross@gb.swissbank.com


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

Date: 4 Jun 1997 20:54:40 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: simple question about running system programs from with  perl.
Message-Id: <5n4kmg$flt$2@dartvax.dartmouth.edu>

In article <339598B6.B9C525E7@cs.montana.edu>
lucas albers <albersl@cs.montana.edu> writes:

> Question: How to run grep from within perl and put the output in a
> string or list.
> Here is what I've tried so far, from the book.
> 
> system('grep "searchstring", filename')
> or
> $output = system('grep');
> That will just return the letter 0, or 1 from the unsuccesful completion
> of a program in unix. $output has the value of 0.

You want to use backticks (``).

Chipmunk


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

Date: Wed, 4 Jun 1997 13:46:05 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: simple question about running system programs from with perl.
Message-Id: <d5d4n5.4k9.ln@localhost>

lucas albers (albersl@cs.montana.edu) wrote:
: Question: How to run grep from within perl and put the output in a
: string or list.
: Here is what I've tried so far, from the book.
                                  ^^^^^^^^^^^^^

What book? Remind me to not buy that one...

Especially since the correct answer is in the free documentation that
***comes with the perl distribution***

(if you have perl, you should have the perl man pages somewhere)


: system('grep "searchstring", filename')
: or
: $output = system('grep');
: That will just return the letter 0, or 1 from the unsuccesful completion
: of a program in unix. $output has the value of 0.


Hmmm. system() is not doing what you expected...

How about using a very radical approach, and reading what the Fine
Perl Man Pages say about the system() command?


from perlfunc man page (I added the underlining):

---------------------------------
=item system LIST

Does exactly the same thing as "exec LIST" except that a fork is done
first, and the parent process waits for the child process to complete.
Note that argument processing varies depending on the number of
arguments.  The return value is the exit status of the program as
returned by the wait() call.  To get the actual exit value divide by
256.  See also L</exec>.  This is I<NOT> what you want to use to capture
                                    ^^^^                      ^^^^^^^^^^
the output from a command, for that you should merely use backticks, as
^^^^^^^^^^^^^^^^^^^^^^^^^                             ^^^^^^^^^^^^^
described in L<perlop/"`STRING`">.
---------------------------------


: I want to run system commands and pass in variables to it.
: So for example you could run grep so that (after aliasig it to whatever)
: so that it will
: prompt you for a searchstring and then a filename before you run it.


Use the docs, Luke.


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


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

Date: Wed, 4 Jun 1997 14:08:31 -0500
From: "Cream" <mferrell@planeteers.com>
Subject: Simple Question
Message-Id: <3395bcc0.0@news.cias.net>

Howdy, sorry about the simplicity of this question but I have a simple perl
script that I need to hack some to simply replace the spaces in one of my
variables with underscores

I have a variable that gets assigned 

$subject = ARGV[0];

and subject can be ( This is a test Subject )
Now I want to set $subject equal to ( This_is_a_test_Subject )

I'm really in a bind here so any help would be greatly appreciated, Thanks
in advance.

Matt Ferrell
mferrell@planeteers.com
972-713-2611





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

Date: 4 Jun 1997 21:04:17 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Simple Question
Message-Id: <5n4l8h$5t2@fridge-nf0.shore.net>

Cream (mferrell@planeteers.com) wrote:

: and subject can be ( This is a test Subject )
: Now I want to set $subject equal to ( This_is_a_test_Subject )

perl -e '$str_1="this is a test"; $str_1 =~ s/\s+/_/g; print
$str_1,"\n";'

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 4 Jun 1997 19:06:58 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: String Compare Problem
Message-Id: <5n4eci$62s$6@dartvax.dartmouth.edu>

In article <MPG.dff4b62ec4b3afc989687@news.tiac.net>
pcartier@ix.netcom.com (Paul Cartier) writes:

> Could someone give me an example on how I can search the
> begining of a string for a match.

^ matches the beginning of a string.
$ matches the end of a string.

Look at man perlre for more information about special characters in
regular expressions.

Chipmunk


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

Date: 4 Jun 1997 20:47:37 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Telnet
Message-Id: <5n4k99$4e8@fridge-nf0.shore.net>

CAD-VISIOGRAPH (visiocad@easynet.fr) wrote:
: can I execute a Telnet with PERL and giving automaticaly the username and
: the password ?

Use the Net::Telnet module, distributed as part of the libnet module.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 04 Jun 1997 14:29:12 -0700
From: Russ Allbery <rra@stanford.edu>
To: Alex `Taker` Pircher <pircher@informatik.tu-muenchen.de>
Subject: Re: Using Variables from shell
Message-Id: <m3wwoacb13.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

Alex `Taker` Pircher <pircher@informatik.tu-muenchen.de> writes:

> I set the Variable OUTPUT in the shell script like this: 
> OUTPUT=anon$PID.html

> Then I start the perl-script: 
> /usr/blabla/perl.pl

> And in the Perl-Script I want to get the Variable OUTPUT:
> $file = $ENV{OUTPUT};

> But everytime it contains nothing. Why that?

Using the Bourne shell?  If so, you forgot to export the environment
variable; if you don't do that, it isn't passed along to any subprocesses,
so Perl never sees it.  Try:

        OUTPUT=anon$PID.html; export OUTPUT

and see if that works any better.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 4 Jun 1997 19:06:13 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: why won't 'print <<end_print...end_print' work?
Message-Id: <5n4eb5$62s$5@dartvax.dartmouth.edu>

In article <3394E922.2526@ils.unc.edu>
Will Sexton <sextw@ils.unc.edu> writes:

> I'd like to thank everyone for responding to my inquiry.  I found the 
> answer (or at least, made it work) from another example I saw.  The 
> second end_print must be flush left against the margin with no white 
> space, but none of the examples I had seen showed a semi-colon on the 
> next line down, also flush left.  When I added that thus
> end_print
> ;
> it worked.

That's because a semicolon by itself is simply a no-op.  If you wanted
to, you could do:
end_print
;
;
;;;;;;
;;
;

And it would still work.

The place you need a semi-colon is on the line where you begin the
here-document.
print <<"end_print";  # <-----

Chipmunk


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

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

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