[15616] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3029 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 12 14:11:26 2000

Date: Fri, 12 May 2000 11:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <958155016-v9-i3029@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 12 May 2000     Volume: 9 Number: 3029

Today's topics:
    Re: Problem: hash introducing extra space on output? (Tad McClellan)
    Re: Problem: hash introducing extra space on output? (Bill)
    Re: Q: Benchmarking hash pre-size <rootbeer@redcat.com>
    Re: Randomised function <andrew.mcguire@walgreens.com>
    Re: Randomised function <sariq@texas.net>
    Re: Regular expression ? <aqumsieh@hyperchip.com>
    Re: Regular expression ? <jeff@vpservices.com>
    Re: Regular expression ? <Frederic.Aussedat@Alcatel.fr>
    Re: Regular expression ? <godzilla@stomp.stomp.tokyo>
    Re: Regular expression ? <jeff@vpservices.com>
    Re: Regular expression ? (Gordon Clemmons)
        Running perl code thru crontab vpanicker@my-deja.com
        sendmail on WinNT <sven.olov_daven@swipnet.se>
    Re: shooting yourself in the foot ... <roman.stawski@fr.adp.com>
    Re: split the big file <aqumsieh@hyperchip.com>
    Re: split the big file nobull@mail.com
    Re: unresolved external in XSUB <rootbeer@redcat.com>
    Re: using Perl's RE to do basic manipulation of a flex  <abe@ztreet.demon.nl>
    Re: Using the preprocessor <rootbeer@redcat.com>
    Re: Using the preprocessor nobull@mail.com
        Using user-variables in external commands? <nobody@mixmaster.shinn.net>
    Re: What is $| ? <gopalan@cs.sc.edu>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 12 May 2000 08:21:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Problem: hash introducing extra space on output?
Message-Id: <slrn8hntqj.ngp.tadmc@magna.metronet.com>

On Fri, 12 May 2000 11:16:26 GMT, Bill <wfeidt@cpcug.org> wrote:

>I resolved it by adding:
>
>  $"="";              <------------
>  %filename =  ("employer.html",    "@employer",
>                "position.html",    "@position",
>                "animals.html",     "@animals",
>  [...]
>
>and now the output reads the way I intended.


Until you want to interpolate an array _with_ spaces later
on in your program.

You should localize the scope of changes to Perl's builtin variables:

{
  local $"="";
  %filename =  ("employer.html",    "@employer",
                 "position.html",    "@position",
                 "animals.html",     "@animals",
   [...]
}



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


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

Date: Fri, 12 May 2000 17:00:40 GMT
From: wfeidt@cpcug.org (Bill)
Subject: Re: Problem: hash introducing extra space on output?
Message-Id: <8F3280EE9wfeidthiscom@207.126.101.97>

tadmc@metronet.com (Tad McClellan) wrote in 
<slrn8hntqj.ngp.tadmc@magna.metronet.com>:

>On Fri, 12 May 2000 11:16:26 GMT, Bill <wfeidt@cpcug.org> wrote:
>
>>I resolved it by adding:
>>
>>  $"="";              <------------
>>  %filename =  ("employer.html",    "@employer",
>>                "position.html",    "@position",
>>                "animals.html",     "@animals",
>>  [...]
>>
>>and now the output reads the way I intended.
>
>
>Until you want to interpolate an array _with_ spaces later
>on in your program.
>
>You should localize the scope of changes to Perl's builtin variables:
>
>{
>  local $"="";
>  %filename =  ("employer.html",    "@employer",
>                 "position.html",    "@position",
>                 "animals.html",     "@animals",
>   [...]
>}

Thanks, Tad.  What I actually ended up with is:

  [...]
  $"="";
  %filename =  ("employer.html",    "@employer",
                "position.html",    "@position",
                "animals.html",     "@animals",
                "business.html",    "@business",
                "environment.html", "@environment",
                "extension.html",   "@extension",
                "food.html",        "@food",
                "genag.html",       "@genag",
                "landscape.html",   "@landscape",
                "other.html",       "@other",
                "plants.html",      "@plants",
                "new.html",         "@new");
  $"=" ";

  foreach (keys %filename)  {
  [...]

Is there a reason not to do it this way?  I guess since the ensuing
statement begins a new block, the two are functionally equivalent?  
Thanks for the insight.

--

Bill Feidt
wfeidt@cpcug.org





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

Date: Fri, 12 May 2000 10:59:33 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Q: Benchmarking hash pre-size
Message-Id: <Pine.GSO.4.10.10005121056440.16364-100000@user2.teleport.com>

On Thu, 11 May 2000, Steven Kuo x7914 wrote:

> I'm trying to evaluate the time saved by pre-sizing a hash
> with the following; is this a valid experiment?

I'd like to think it is. :-)

>     undef my %hash;

That's unusual and the undef is superfluous, but I don't think it relates
to the behavior you're seeing.

> Benchmark: timing 100 iterations of NoPresize, Presize...
>  NoPresize: 27 secs (26.27 usr  0.03 sys +  0.00 cusr  0.00 csys = 26.30
> cpu)
>    Presize: 25 secs (25.27 usr  0.00 sys +  0.00 cusr  0.00 csys = 25.27
> cpu)

Well, I can't see the flaw in your methods. Although I've tried several
variants in your code, I can't make an example which shows a significant
time savings for presizing. Either there's a flaw in our methods, or
presizing just isn't a big deal. 

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 12 May 2000 10:05:39 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Randomised function
Message-Id: <391C1DC3.721B2D21@walgreens.com>

Mike Moose wrote:
> 
> Hi, I'm trying to write a perl function which will generate a random
> password of 8 character, numbers/characters ... in C there is rand()
> which generates a random number synched with the time, is there a
> function similar to this in Perl...

Nope, Im afraid your stuck with C. ;^)

perldoc -f rand

Cheers,

anm
-- 
Andrew N. McGuire
andrew.mcguire@walgreens.com


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

Date: Fri, 12 May 2000 10:12:05 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Randomised function
Message-Id: <391C1F45.7BAAFF4F@texas.net>

Mike Moose wrote:
> 
> Hi, I'm trying to write a perl function which will generate a random
> password of 8 character, numbers/characters ... in C there is rand()
> which generates a random number synched with the time, is there a
> function similar to this in Perl...
> 
> Thanks

Perl's functions are documented in the perlfunc manpage.  Perhaps you'll
find something similar to C's rand() function there...

Good luck with it!

- Tom


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

Date: Fri, 12 May 2000 15:39:14 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Regular expression ?
Message-Id: <7azopv7p7h.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


Matthew Stoker <matt.stoker@motorola.com> writes:

> Jeff Zucker wrote:
> > 
> > tvn007@my-deja.com wrote:
> > >
> > > sorry, the input file is more complicate so I do not think I can use
> > > split.
> > >
> > > The actual input file would be something like this:
> > >         abc   : 0_0  2.02  A
> > >         305   : 0_0  2.01  A
> > >         306   : 0_0  1.80  AR
> > >         305   : 0_0  2.50  AR
> > >
> > 
> > That would work exactly the same as the other with the split.  The only
> > thing that would break the split would be if there were a different
> > number of non-whitespace elements before the one you want to catch.
> 
> Except if I understand, he wouldn't want to get 2.02 when the first
> column contains non-numeric values.  In which case this would work:
> 
> 
>    while(<DATA>) {
>        my @ary = split " "; # use " " instead of /s+/ to
>                             # ignore leading white space
>        print "$ary[3]\n" unless ($ary[0]=~/\D/);
>    }

which brings us to the question : Does something like 3.6 contain any
'non-numeric' values?

I would simply use a regexp and use \S+ and get it over with.

--Ala


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

Date: Fri, 12 May 2000 09:48:35 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Regular expression ?
Message-Id: <391C35E3.C7553251@vpservices.com>

"Godzilla!" wrote:
> 
> tvn007@my-deja.com wrote:
> 
> > Could someone please help me with the following pattern matching ?
> 
> > Here is the data:
> 
> > 305   : 0_0  2.01  A
> > 306   : 0_0  1.80  AR
> > 305   : 0_0  2.50  AR
> 
> > I would like to extract number 2.01, 1.80 and 2.50
> 
> 305¦0_0¦2.01¦A
> 
> Leaving out spaces and using a non-volatile
> delimiter would reduce this data extraction
> to a very simple split operation, 

Yes, good advice to switch to a pipe in case the OP ever has whitespace
inside a field.

> This code, in both examples, pre-conditions your
> data base by reducing all white space to a single
> space,

Totally unnecessary since regular expressions can match a group of
whitespaces as easily as they can match a single whitespace.

> I have written this code to demonstrate
> how to capture all variables, beyond the
> single variable of interest to you. 

Yes, good idea if this is more than a one-time throw-away script.

> For fun in playing around, I have designed
> my code to exhibit what some would refer
> to as a "bug".

Yes, good idea to encourage people to experiment, to have fun, and to
never ever copy Godzilla's code verbatim.   And to never copy anyone's
code without thinking about the consequences.

> open (TEST, "test.txt");

Failure to test if the open succeeded.

> @Test_Array_1 = <TEST>;

Unnecessary reading an entire file into an array rather than looping
through lines as they are read.

>   $test_line_1 =~ s/ (.*) : (.*) (.*) (.*)/$1$2$3$4/;

Bound to fail if there is any variation in the data format at all (e.g.
extra spaces or tabs instead of spaces), as you obliquely pointed out
with your mention of the "bug".

>   local ($key, $value) = split (/:/, $test_line_2);

This first split is unneeded, why introduce it?

>   local ($var2, $var3, $var4) = split (/ /, $value);

Yes, a split is a good idea.  But again it should be on whitespace not a
single space character.  And  one should use "my" instead of "local". 
Also, putting the result of the split into named individual variables is
not as flexible as putting it into an array.  If it is put into an array
(as in my example in this same thread), then if the number of fields
changes in the future, the only thing that needs to be changed is the
index of the array.  Your way does work for the exact data submitted
though.


-- 
Jeff


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

Date: Fri, 12 May 2000 18:55:42 +0200
From: Frederic Aussedat <Frederic.Aussedat@Alcatel.fr>
Subject: Re: Regular expression ?
Message-Id: <391C378E.34C854D4@Alcatel.fr>

Just bad regular expression :
use :
	/^\d+\s*:\s*0_0\s*(\d\.\d+)\s*[A-R]+/)
it should work.

Regards


tvn007@my-deja.com a écrit:
> 
>  Hi,
> 
> Could someone please help me with the following pattern matching ?
> 
> Here is the data:
> 
> 305   : 0_0  2.01  A
> 306   : 0_0  1.80  AR
> 305   : 0_0  2.50  AR
> 
> I would like to extract number 2.01, 1.80 and 2.50
> 
> Here is what I have, and it does not work (i.e does not print out
> anything)
> 
> if($_ =~ /^[0-9]\s*:\s*0_0\s*([0-9])\s*[A-R]/)
> 
>         print "$_\n";
>         print  "$1\n";
> 
> Thanks in advance for  any help,
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.


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

Date: Fri, 12 May 2000 10:24:17 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regular expression ?
Message-Id: <391C3E41.CE517A49@stomp.stomp.tokyo>

Jeff Zucker wrote:

(misc. snippage)
 
> "Godzilla!" wrote:

> > tvn007@my-deja.com wrote:

> > > Could someone please help me with the following pattern matching ?


> > 305¦0_0¦2.01¦A

> > Leaving out spaces and using a non-volatile
> > delimiter would reduce this data extraction
> > to a very simple split operation,
 
> Yes, good advice to switch to a pipe in case the OP 
> ever has whitespace inside a field.


What you are looking at is not a pipe symbol.

*shrugs*

 
> ...And  one should use "my" instead of "local".


Seven very good reasons to use local over my, and
some interesting notes on slurping being more
efficient than use of while.

http://www.plover.com/~mjd/perl/local.html


Do your homework before responding to my articles.


Godzilla!


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

Date: Fri, 12 May 2000 10:38:00 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Regular expression ?
Message-Id: <391C4178.CFAEC775@vpservices.com>

"Godzilla!" wrote:

> > > 305¦0_0¦2.01¦A

> > Yes, good advice to switch to a pipe in case the OP
> > ever has whitespace inside a field.
> 
> What you are looking at is not a pipe symbol.

Oh?  That's what it is commonly called even when not used to pipe
information from one place to another.  The common term "pipe delimited"
refers to that exact kind of data even if somewhat untechnically. 
What's the matter do you have problems accepting compliments?  I was
agreeing with you.

> > ...And  one should use "my" instead of "local".

> Seven very good reasons to use local over my,

The first line of which says : "my makes most uses of local obsolete"
and your use of it here definitely fits into the "most uses" category.
 
> some interesting notes on slurping being more
> efficient than use of while.

In certain very specialized circumstances, none of which apply to your
use of it in that script.

> Do your homework before responding to my articles.

Or better yet, why even respond at all, you never listen to anything.  I
am a fool for even trying to communicate with you.  Ha ha, what an idiot
Jeff is.

-- 
Jeff


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

Date: 12 May 2000 17:41:03 GMT
From: perl_phreak@yahoo.com (Gordon Clemmons)
Subject: Re: Regular expression ?
Message-Id: <8F326C1B7nospamblahcom@206.165.3.80>

>tvn007@my-deja wrote:

>sorry, the input file is more complicate so I do not think I can use
>split.
>
>The actual input file would be something like this:
>        abc   : 0_0  2.02  A
>     305   : 0_0  2.01  A
>     306   : 0_0  1.80  AR
>      305   : 0_0  2.50  AR

Perlgolf anyone?

print + (split /\s+/, $_)[4] . "\n" while (<DATA>);


__DATA__
        abc   : 0_0  2.02  A
	305   : 0_0  2.01  A
	306   : 0_0  1.80  AR
 	305   : 0_0  2.50  AR

I can't wait to see the gurus post a 3 character reply and smoke me:)

-- Gordon


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

Date: Fri, 12 May 2000 17:34:11 GMT
From: vpanicker@my-deja.com
Subject: Running perl code thru crontab
Message-Id: <8fhfaj$btm$1@nnrp1.deja.com>

I am facing problems running a perl code thru the crontab , as my env
variable LD_LIBRARY_PATH is not getting set, which is not letting me
call shared libraries. It seems %ENV in perl passes impoverished env.
setting in cronjobs.

Can anyone suggest a way out on this.
Thanx
With regards
vinod


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


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

Date: Fri, 12 May 2000 19:59:31 +0200
From: "DAVÉN SVEN-OLOV" <sven.olov_daven@swipnet.se>
Subject: sendmail on WinNT
Message-Id: <%EXS4.1377$JL6.4294@nntpserver.swip.net>

How do I send mail in a Windows NT Perl script?

--
Christian Davén
cyner@home.se
http://hem.passagen.se/cyner

"No one gets out of this world alive,
so the time to live, learn, care,
share, celebrate, and love is now."




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

Date: Fri, 12 May 2000 17:30:58 +0200
From: Roman Stawski <roman.stawski@fr.adp.com>
Subject: Re: shooting yourself in the foot ...
Message-Id: <391C23B2.90F1D674@fr.adp.com>

Tad McClellan wrote:
> 
>    Foot::Ball        (DWIMs between pointy-ended ball and soccer varieties
>                       based on locale)
> 

Can't DWIM this everywhere... you couldn't necessarily distinguish 
between a preference for rugby football or soccer from the locale.
Hmmm, perhaps the locale should be extended in order to handle this...
after all this is vital in many production systems.

-- 
Roman Stawski - ADPgsi


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

Date: Fri, 12 May 2000 15:32:42 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: split the big file
Message-Id: <7a3dnn942s.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


Samay <samay1NOsaSPAM@hotmail.com.invalid> writes:

> I am looking for effective ways for code and performance.
> My patterns are simple strings.
> such as 'japan' or '/america/newyork/'
> 
> I did..
> open FILE1, ">file1";
> open FILE2, ">file2";
> .
> open FILE50,">file50";
> 
> 
> while(<IN>){
>    if(/pattern1/){
>       print FILE1;
>       next;
>    }
>    if(/pattern2/){
>       print FILE2;
>       next
> 
> ..for 50 patterns..
> }
> 
> 
> This will give me average time.. I am looking for something
> better. Memory could be issue, space is not an issue..

Well, the best approach I can think of is to use a hash to associate
patterns with filehandles (I would use objects of the IO::File instead
of globs):

	my %map = (
		   pattern1 => new IO::File '>file1' or \*STDOUT,
		   pattern2 => new IO::File '>file2' or \*STDOUT,
		   ....
		  );

Then you could either loop through the keys of %map:

	while (<IN>) {
		for my $pat (keys %map) {
			if (/\Q$pat/) {
				print {$map{$pat}} $_;
				next;
			}
		}
	}

Or, you could do something like (untested):

	my $pats = "(" . (join '|' => keys %map) . ")";
	
	while (<IN>) {
		if (/$pats/) {
			print {$map{$1}} $_;
			next;
		}
	}

which could be faster than the approach above it, but would break if $pats
compiles to more than 32767 bytes.

Also, you might want to quotemeta() your keys:

	my $pats = "(" . (join => map quotemeta => keys %map) . ")";

to protect any special characters in the keys that you want to match
literally.

--Ala


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

Date: 12 May 2000 17:23:23 +0100
From: nobull@mail.com
Subject: Re: split the big file
Message-Id: <u966sjrb44.fsf@wcl-l.bham.ac.uk>

Samay <samay1NOsaSPAM@hotmail.com.invalid> writes:

> Hi, I have log file with size around 500 MB. I would like to
> divide into small files based upon the particular word it
> contains.. What are the effective ways?
> 
> I am looking for effective ways for code and performance.
> My patterns are simple strings.
> such as 'japan' or '/america/newyork/'

If they really are simple strings then pattern match is probably not
the way.  Do these words aleays appear in the same (or at least a
recognisable) position with the line? In that case it is better to
extract the keyword (with split() or m//) and use it as a key into a
hash full of filehandles.

Suppose you want to split based on the word in the second column and
use the word as a filename.

use strict;
use IO::File;
my %files;
while(<>) {
  my $word = (split)[1];
  ( $files{$word} ||= IO::File->new($word,'w') or die )->print;
}

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


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

Date: Fri, 12 May 2000 09:29:25 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: unresolved external in XSUB
Message-Id: <Pine.GSO.4.10.10005120926450.16364-100000@user2.teleport.com>

On Fri, 12 May 2000 energon@my-deja.com wrote:

> Environment: Solaris 2.6 and HP-UX 10.20  with Perl 5.002

> However, I get the following error
> /usr/lib/dld.sl: Unresolved symbol: XS_unpack_charPtrPtr (code)  from
> ./mytest.sl
> on my HP-UX 10.20 box when I try to run my test.

I'd guess that you should upgrade perl on one or both of these machines,
then make sure that the XS code works with the new perl. 5.002 is _quite_
old, having been last maintained over four years ago, and missing out on
the major security update in the summer of 1996.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 12 May 2000 19:24:51 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: using Perl's RE to do basic manipulation of a flex file
Message-Id: <53fohs8ca94au3mqvccq7k53bd9ekpsmiu@4ax.com>

On Tue, 09 May 2000 23:07:51 GMT, Ron Grabowski <ronnie@catlover.com>
wrote:

> I want to change:
> 
> [A-Za-z]{DIGIT}      {some_function(); return ALPHA_WITH_DIGIT_TOKEN;}
> {ANOTHER_TOKEN}[0-9] {   blah( )   ;  return   TOKEN2  ;  }
> 
> into
> 
> [A-Za-z]{DIGIT}      { printf("[ALPHA_WITH_DIGIT_TOKEN] %s",yytext); }
> {ANOTHER_TOKEN}[0-9] { printf("[TOKEN2] %s", yytext); }
> 
This will break with nested blocks in braces or quoted braces in a 'to
replace' block, but it works on the sample data:

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

{local $/; $_ = <DATA>;}

print "Before:\n$_";

s#{[^}]*return\s+(\w+)[^}]*}#{ printf("[$1] %s", yytext); }#g;

print "\nAfter:\n$_";

__DATA__
[A-Za-z]{DIGIT}      {some_function(); return ALPHA_WITH_DIGIT_TOKEN;}
{ANOTHER_TOKEN}[0-9] {   blah( )   ;  return   TOKEN2  ;  }

-- 
Good luck,
Abe


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

Date: Fri, 12 May 2000 09:24:07 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Using the preprocessor
Message-Id: <Pine.GSO.4.10.10005120919010.16364-100000@user2.teleport.com>

On Fri, 12 May 2000, Daniel Garcia Fernandez wrote:

> I have put some preprocesor in a perl script. All goes well when i run
> it under unix, but when i try "perl -P" under win32 I get this message
> "Error: Parse exception".

That's one of the best reasons why you shouldn't use the preprocessor.
It's not portable. You should probably re-code to avoid it. 

I should mention that there's been some talk about using the Filter module
to do the preprocessing, if you can get it to work portably. 

    http://search.cpan.org/search?dist=Filter

But implementing cpp may be a larger challenge than you were hoping for
today. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 12 May 2000 17:30:40 +0100
From: nobull@mail.com
Subject: Re: Using the preprocessor
Message-Id: <u94s83rarz.fsf@wcl-l.bham.ac.uk>

Daniel Garcia Fernandez <danielg@tid.es> writes:

> it under unix, but when i try "perl -P" under win32 I get this message
> "Error: Parse exception".
> Why happens this ?
> How can I solve It?

Don't use the preprocessor (which is external to Perl) if you can help
it.

What you want to do (conditional "use") can be done simply by
breaking "use" into it's consituent parts (see "perldoc -f use") and
inserting an "if" in the obvious place.

> --------------85F1AEB87E7010032BC055C0
> Content-Type: text/x-vcard; charset=us-ascii;
>  name="danielg.vcf"

Do not do this, this is not a binary newsgroup.

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


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

Date: Fri, 12 May 2000 07:57:34 -0400
From: Anonymous Sender <nobody@mixmaster.shinn.net>
Subject: Using user-variables in external commands?
Message-Id: <11ca6ec0dac77212155a826d847f7b2a@mixmaster.shinn.net>

Hi all,

I know that I have to escape chars if
I use something like that:

system("sendmail $recipient");

because someone can do nasty things with
that, but how is it if I use the following:

open(MAIL,"| sendmail");
print <<MAIL;
To: $recipient

$body
end
close(MAIL);

Can someone here also do nasty things?
And how can I savely send mails by
allowing _all_ characters?

Thank you for your help, Mike!

-----------------------------------------------------------
Posted with AnonNews at http://anonymouse.home.pages.de/


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

Date: Fri, 12 May 2000 11:00:10 -0400
From: Gopi Sundaram <gopalan@cs.sc.edu>
Subject: Re: What is $| ?
Message-Id: <Pine.OSF.4.21.0005121053460.10054-100000@pearl.cs.sc.edu>

On Fri, 12 May 2000, Makau Divangamene wrote:

> Any illustrated examples of $| would be pretty much appreciated ..

Okay, here we go:

----------------
Code Sample 1:

#!/usr/bin/perl -w

use strict;

print STDOUT "This is standard output";
print STDERR "This is standard error\n";
-----
IF YOU ARE ON A TERMINAL, this will result in the output:

	This is standard error
	This is standard output

This is because the '\n' cause STDERR to flush before STDOUT, and if
you are on a terminal, both are sent to the screen.

--------------
Code Sample 2:

#!/usr/bin/perl -w

use strict;

select STDOUT;
$|++;
select STDERR;
$|++;

print STDOUT "This is standard output";
print STDERR "This is standard error\n";
-----
IF YOU ARE ON A TERMINAL, this will result in the output

	This is standard outputThis is standard error

because the output buffers were flushed as soon as "print" finished.

Please note that you have to explicitly set $| for every stream.

Hope this helps.

-- 
Gopi Sundaram
gopi@cs.sc.edu



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3029
**************************************


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