[25893] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8121 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 27 14:05:32 2005

Date: Fri, 27 May 2005 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 27 May 2005     Volume: 10 Number: 8121

Today's topics:
        finding the PID of a process running as an anonymous pi <user@host.com>
    Re: finding the PID of a process running as an anonymou (Anno Siegel)
    Re: finding the PID of a process running as an anonymou <"nospam at mythicalbeast dotco dotuk">
    Re: Force interpolation of single quoted character <shawn.corey@sympatico.ca>
    Re: Force interpolation of single quoted character <usenet739_yahoo_com_au>
    Re: Force interpolation of single quoted character <nobull@mail.com>
    Re: Force interpolation of single quoted character <nobull@mail.com>
    Re: Force interpolation of single quoted character <tadmc@augustmail.com>
    Re: Force interpolation of single quoted character <usenet739_yahoo_com_au>
    Re: FormMail Problem <noreply@gunnar.cc>
    Re: FormMail Problem <tadmc@augustmail.com>
    Re: Ignorant question regarding includes <mddibern@NOSPAM.student.cs.uwaterloo.ca>
        LWP::UserAgent credentials netloc and realm <john.stumbles@ntlworld.com>
    Re: output question <tadmc@augustmail.com>
    Re: output question <vdotniekerkatfreelerdotnl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 27 May 2005 13:31:29 GMT
From: "Richard" <user@host.com>
Subject: finding the PID of a process running as an anonymous pipe
Message-Id: <RiFle.668$_k2.11897@news2.nokia.com>

I need to find the PID of a process running as an anonymous pipe, that is I
have this code

   $fh = new FileHandle;
   open($fh, "tail -f $filename |") or die ..........

I want to get the PID of the tail -f process when runing under linux, I
could do it by looking at the output of ps -fwu $userid | grep "tail -f
$filename", but that seems like over kill :-)

Thanks.
Richard.




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

Date: 27 May 2005 14:39:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: finding the PID of a process running as an anonymous pipe
Message-Id: <d77bf6$n6u$1@mamenchi.zrz.TU-Berlin.DE>

Richard <user@host.com> wrote in comp.lang.perl.misc:
> I need to find the PID of a process running as an anonymous pipe, that is I
> have this code
> 
>    $fh = new FileHandle;
>    open($fh, "tail -f $filename |") or die ..........
> 
> I want to get the PID of the tail -f process when runing under linux, I
> could do it by looking at the output of ps -fwu $userid | grep "tail -f
> $filename", but that seems like over kill :-)

"perldoc -f open" will answer that.  Also see "perldoc -q tail".

Anno


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

Date: Fri, 27 May 2005 17:56:38 +0100
From: Richard <"nospam at mythicalbeast dotco dotuk">
Subject: Re: finding the PID of a process running as an anonymous pipe
Message-Id: <42975150$0$13905$ed2619ec@ptn-nntp-reader01.plus.net>

DOH!  Thanks :-)

Please accept my humble apologies for not RTFM :-)

Anno Siegel wrote:
> Richard <user@host.com> wrote in comp.lang.perl.misc:
> 
>>I need to find the PID of a process running as an anonymous pipe, that is I
>>have this code
>>
>>   $fh = new FileHandle;
>>   open($fh, "tail -f $filename |") or die ..........
>>
>>I want to get the PID of the tail -f process when runing under linux, I
>>could do it by looking at the output of ps -fwu $userid | grep "tail -f
>>$filename", but that seems like over kill :-)
> 
> 
> "perldoc -f open" will answer that.  Also see "perldoc -q tail".
> 
> Anno


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

Date: Fri, 27 May 2005 07:53:05 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: Force interpolation of single quoted character
Message-Id: <CSDle.23740$Ot6.1415546@news20.bellglobal.com>

Scott Bass wrote:
> Hi,
> 
> use Getopt::Long;
> GetOptions (
>   "sep:s" => \$sep
>   );
> $sep = "$sep";  # doesn't work
> print "line1",$sep,"line2";
> 
> If I invoke this as --sep \n or --sep \t, how can I force the interpolation 
> of the escapse sequence?
> 
> Thanks,
> Scott 
> 
> 

eval '$sep = "$sep";';

    --- Shawn


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

Date: Fri, 27 May 2005 22:35:12 +1000
From: "Scott Bass" <usenet739_yahoo_com_au>
Subject: Re: Force interpolation of single quoted character
Message-Id: <42971401$0$11235$5a62ac22@per-qv1-newsreader-01.iinet.net.au>


"Shawn Corey" <shawn.corey@sympatico.ca> wrote in message 
news:CSDle.23740$Ot6.1415546@news20.bellglobal.com...
> Scott Bass wrote:
>> Hi,
>>
>> use Getopt::Long;
>> GetOptions (
>>   "sep:s" => \$sep
>>   );
>> $sep = "$sep";  # doesn't work
>> print "line1",$sep,"line2";
>>
>> If I invoke this as --sep \n or --sep \t, how can I force the 
>> interpolation of the escapse sequence?
>>
>> Thanks,
>> Scott
>
> eval '$sep = "$sep";';
>
>    --- Shawn

test1.pl:

use Getopt::Long;
GetOptions (
  "sep:s" => \$sep
  );
eval '$sep = "$sep";';
print "line1",$sep,"line2";

C:\> test.pl -sep "\n"

gives me

line1\nline2

BTW, ActiveState Perl on Windows - wouldn't think that matters though. 




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

Date: Fri, 27 May 2005 13:49:29 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Force interpolation of single quoted character
Message-Id: <d77510$cu2$1@redhat2.bham.ac.uk>



Shawn Corey wrote:
> Scott Bass wrote:
> 
>> Hi,
>>
>> use Getopt::Long;
>> GetOptions (
>>   "sep:s" => \$sep
>>   );
>> $sep = "$sep";  # doesn't work
>> print "line1",$sep,"line2";
>>
>> If I invoke this as --sep \n or --sep \t, how can I force the 
>> interpolation of the escapse sequence?

This is of course one FAQ.

And very similar to another one.

And as regular readers will know I find the fact that the answers given 
in the FAQ pretends the simple/obvious/direct answer does not exist a 
constant source of annoyance.

I even gave a lightning talk at YAPC::Europe::2004 about it.

This is because it means that people get shown (or figure out for 
themselves) the broken form of the obvious answer...

> eval '$sep = "$sep";';

 ... yes, that's the one.  That breaks if $sep contains double quote 
characters.

The better version of that is...

   chop( $sep = eval "<<__EOD__\n$sep\n__EOD__");
   do_something if $@;

That only breaks if $sep contains the sequence "\n__EOD__\n" which is 
much less likely to occur in the normal course of events.


And also by excuding this "dangerous knowledge" from the FAQ the real 
effect is that people are simply are not warned of the security dangers 
of using eval(STING) on data that could come from someone who doesn't 
have a ligitmate way of getting full shell access (under the current 
effective UID).

Note: for expanding escapes rather than interpolating variables the 
solution in the FAQ is probably better anyhow.



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

Date: Fri, 27 May 2005 13:57:51 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Force interpolation of single quoted character
Message-Id: <d775ge$cu2$2@redhat2.bham.ac.uk>



Brian McCauley wrote:

> the broken form of the obvious answer...
> 
>> eval '$sep = "$sep";';
> 
> ... yes, that's the one.

Oops, no it's not even that.

The 'correct' broken form is...

   eval qq'$sep = "$sep";';

But it's still better to use the less broken form, or better still the 
FAQ solution.



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

Date: Fri, 27 May 2005 10:04:56 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Force interpolation of single quoted character
Message-Id: <slrnd9edoo.ci8.tadmc@magna.augustmail.com>

Scott Bass <> wrote:
> Hi,
> 
> use Getopt::Long;
> GetOptions (
>   "sep:s" => \$sep
>   );
> $sep = "$sep";  # doesn't work
> print "line1",$sep,"line2";
> 
> If I invoke this as --sep \n or --sep \t, 


Then you would have  $sep eq 'n' or $sep eq 't', so I'll assume that
you meant

   --sep '\n'

instead.


> how can I force the interpolation 
> of the escapse sequence?


I would solve the problem without the need for forcing interpolation.

 ------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;

our $sep;
GetOptions (
  "sep:s" => \$sep
  );

my %separators = (
   '\n' => "\n",
   '\t' => "\t"
);
die "'$sep' is not a valid separator\n" unless $sep =~ /^(\\[tn])$/;

$sep = $separators{$sep};
print "line1",$sep,"line2";
print "\n";
 ------------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 28 May 2005 03:22:19 +1000
From: "Scott Bass" <usenet739_yahoo_com_au>
Subject: Re: Force interpolation of single quoted character
Message-Id: <4297574d$0$11215$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

"Tad McClellan" <tadmc@augustmail.com> wrote in message 
news:slrnd9edoo.ci8.tadmc@magna.augustmail.com...
> Scott Bass <> wrote:
>> Hi,
>>
>> use Getopt::Long;
>> GetOptions (
>>   "sep:s" => \$sep
>>   );
>> $sep = "$sep";  # doesn't work
>> print "line1",$sep,"line2";
>>
>> If I invoke this as --sep \n or --sep \t,
>
>
> Then you would have  $sep eq 'n' or $sep eq 't', so I'll assume that
> you meant
>
>   --sep '\n'
>
> instead.

Yes, command line options of -sep \n, -sep \t, etc.  However, -sep \n, -sep 
"\n", or -sep '\n' all seem to give the same results after processing by 
GetOptions.

>> how can I force the interpolation
>> of the escapse sequence?
>
>
> I would solve the problem without the need for forcing interpolation.
>
> ------------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Getopt::Long;
>
> our $sep;
> GetOptions (
>  "sep:s" => \$sep
>  );
>
> my %separators = (
>   '\n' => "\n",
>   '\t' => "\t"
> );
> die "'$sep' is not a valid separator\n" unless $sep =~ /^(\\[tn])$/;
>
> $sep = $separators{$sep};
> print "line1",$sep,"line2";
> print "\n";

Sorry I oversimplied my post for the purpose of brevity.  I'd like the users 
of my script to be able to specify, for example:

-sep \n=====\n
-sep \n\n\n\
-sep \t
-sep #

etc.

Brian, based on your replies, I skimmed all the FAQ's, esp. perlfaq4.  Can I 
have a hint as to which FAQ this is explained?

> ------------------------------
>
>
> -- 
>    Tad McClellan                          SGML consulting
>    tadmc@augustmail.com                   Perl programming
>    Fort Worth, Texas 




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

Date: Fri, 27 May 2005 13:39:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FormMail Problem
Message-Id: <3fog7bF8ophlU1@individual.net>

Sherm Pendley wrote:
> Gunnar Hjalmarsson wrote:
>> There is a fairy tale for kids about the peril of repeated, 
>> unwarranted warnings which is applicable to this discussion. 
>> Unfortunately I don't know its name...
> 
> "The Boy Who Cried Wolf" by Aesop:
> 
>     <http://tomsdomain.com/aesop/id87.htm>

Thanks, Sherm! :)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Fri, 27 May 2005 09:16:38 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: FormMail Problem
Message-Id: <slrnd9eau4.ci8.tadmc@magna.augustmail.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Tad McClellan wrote:
>> Gunnar Hjalmarsson wrote:
>>> Anno Siegel wrote:
>>>> Gunnar Hjalmarsson wrote:
>>>>> And that explains this unnecessary thread just because I pointed out 

> It's obvious from Christopher's follow-up that he doesn't know enough 
> Perl 


I didn't see anything in his followup that indicated a skill level.

I must have missed the obvious, what was it that you saw?


> to express such a depreciatory opinion on someone else's code, and 
> that his opinion is merely hearsay.
> 
> Defending such a conduct is not a wise thing to do.


I could agree with that IF it be could established as hearsay.


> There is a fairy tale for kids about the peril of repeated, unwarranted 
> warnings which is applicable to this discussion. Unfortunately I don't 
> know its name...


You are probably thinking of "The Boy Who Cried Wolf".

I'd have to disagree that warning people off of crappy code 
is "unwarranted" though.


>> Telling them to NOT learn from crappy example code *is* really important.
> 
>    s/telling/convincing/
> 
> That replacement makes the meaning of the sentence significantly 
> different. ;-)


You are right, that would be better, but it would take much longer.

When faced with choosing from:

   1) convincing them at the expense of many followups or much time.

   2) telling them at the expense of about 20 seconds.

   3) saying nothing and letting them learn the hard way.

those pressed for time might be more soft-hearted than simply 
going with #3.  :-)

Most particularly when they have already participated in a dozen 
or so previous #1-ish iterations (ie. they've done their time).


Mom often tells me to "look both ways before crossing the street".

She will, of course, explain why if I ask. But after a couple of
rounds of her explaining and me forgetting, she's likely to
revert to simply telling me once again.

Keeping me from getting hit by a bus is "warranted" from
my point of view, I like being around.  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 27 May 2005 09:52:19 -0400
From: Debo <mddibern@NOSPAM.student.cs.uwaterloo.ca>
Subject: Re: Ignorant question regarding includes
Message-Id: <Pine.GSO.4.58.0505270948520.23996@rees.math.uwaterloo.ca>


TM> > ***In constants.pl:
TM> >
TM> > my $constant1 = 'some value';
TM>   ^^
TM> > my $constant2 = 'some other value';
TM>
TM> Lexical variables are never visible across file boundaries,
TM> for that you need the other kind of variable (package variables).


Well, that was sort of the crux of my problem in the first place. This was
more of a conceptual example of what I wanted more than anything.


TM> > ***In somefile.pl:
TM> >
TM> > require constants.pl;
TM>
TM>
TM> require requires a string.
TM>
TM> You should put quotes around strings.


Again, I was just illustrating in general what I wanted to do.


TM> Make a proper module and export the variables via Exporter.
TM>
TM> Perhaps even better, have a single global hash instead of
TM> a "whole bunch" of individual variables.

Both sound like very good ideas... my problem with the latter is I get
tired of writing the name of the darn hash all the time :) Laziness is
part of the reason I picked up perl in the first place...

I'm going to look into this Exporter thingie, it sounds like something I
should know about. Thanks very much.

-Debo


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

Date: Fri, 27 May 2005 17:56:17 GMT
From: John Stumbles <john.stumbles@ntlworld.com>
Subject: LWP::UserAgent credentials netloc and realm
Message-Id: <5bJle.612$wJ6.181@newsfe4-gui.ntli.net>

Googling for how to get this to work I found that I'm not the only one to
have difficulties. I eventually found the answer at
http://groups-beta.google.com/group/comp.lang.perl.misc/browse_frm/thread/5cf8c33182974059/

Summary: you have to include the port no in the 'netloc' variable e.g.
    credentials("http://abc.com:80", "realm", "uname", "passwd");

The other thing that threw a lot of people, including me, was what exactly
'netloc' and 'realm' are. 'realm' is whatever the server is configured to
ask you e.g. "Enter username and password for foo at abc.com".

It would be nice to have this explained in the docs but as a 2nd best I hope
this will come up closer to the top of a google search for anyone asking in
future.


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

Date: Fri, 27 May 2005 10:16:11 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: output question
Message-Id: <slrnd9eedr.ci8.tadmc@magna.augustmail.com>

Huub <> wrote:
> 
> Posted it some time ago in another group without getting an answer. In 
> the meantime I got that one, so your answer is a confirmation....missing 
> a "." indeed. Yet, when I have the terminator in place like this:
> 
> # Declaratie format
> format OUTPUT_FILE =
> .


The format is empty, so it will write() nothing, just like you 
told it to. It is roughly equivalent to:

   print '';

You need to read the documentation for format() yet again.



You do know that you don't need format() to make output, don't you?


> {do something}
> open(OUTPUT_FILE,">UITBESTAND") || die("Fout met openen te schrijven 
> bestand");
> write(OUTPUT_FILE);
> close(OUTPUT_FILE);
> 
> UITBESTAND stays empty and I can't figure out why.


What were you expecting instead?

The code is doing exactly what you told it to do.

If you want it to do something else, then tell it to do something else.

If you don't know how to tell perl to do that something else, then
tell *us* what the something else is. We are not mind readers.


> Also, is it possible to give arguments with perl, like:
> 
> perl <x.pl>  <file to read> <word to check for>


Yes.


> If not, it'll save me the time looking for it.


So you better start looking then.

Start with the @ARGV variable in

   perldoc perlvar


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 27 May 2005 18:47:56 +0200
From: Huub <vdotniekerkatfreelerdotnl>
Subject: Re: output question
Message-Id: <42974f11$0$154$3a628fcd@reader2.nntp.hccnet.nl>

> The format is empty, so it will write() nothing, just like you 
> told it to. It is roughly equivalent to:
> 
>    print '';
> 
> You need to read the documentation for format() yet again.
> You do know that you don't need format() to make output, don't you?

 From the tutorial I'm studying, I understood I needed format() to write to an outputfile.

> If you don't know how to tell perl to do that something else, then
> tell *us* what the something else is. We are not mind readers.

I know, I just thought I gave enough info. If I didn't, sorry for that.

> 
> So you better start looking then.
> 
> Start with the @ARGV variable in
> 
>    perldoc perlvar
> 
Thank you.


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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 8121
***************************************


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