[8368] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1985 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 27 08:07:31 1998

Date: Fri, 27 Feb 98 05:02:33 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 27 Feb 1998     Volume: 8 Number: 1985

Today's topics:
    Re: Lexical scoping of variables Frank@but_dont_use_this.address
    Re: many ways but i can not find one (avm)
    Re: many ways but i can not find one <star@sonic.net>
    Re: many ways but i can not find one (Martien Verbruggen)
        my first associative array <mr.Nostrils@chronotope.com>
        Perl Purify'd? <jdporter@min.net>
        Perl Workshop <dmurray@dgesolutions.com>
        Perl/CGI programmer needed..... <amackey@tenforward.com>
        problem installing Perl - Solaris x86 <wbjones@msn.com>
    Re: removing new line (\n) (Craig Berry)
    Re: seeking and changing /etc/passwd <grimoire@oaktree.net>
    Re: seeking and changing /etc/passwd (Martien Verbruggen)
    Re: seeking and changing /etc/passwd (Martien Verbruggen)
    Re: seeking and changing /etc/passwd (Martien Verbruggen)
    Re: sending text to command line <jwb79@mail.idt.net>
        stumper: fun with perl <danboo@negia.net>
    Re: The Ineffable Tom C. (Peter Samuelson)
    Re: Two questions about POD (Martien Verbruggen)
    Re: use system or backticks?? <vallon@pearl.fi.bear.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 27 Feb 1998 08:58:06 +0100
From: Frank@but_dont_use_this.address
Subject: Re: Lexical scoping of variables
Message-Id: <yo9sop5h435.fsf@nym.sc.philips.com>

Tom Christiansen <tchrist@mox.perl.com> writes:

> 
> In comp.lang.perl.misc, 
>     Frank@but_dont_use_this.address writes:
> :Hello!
> :
> :I just fall into some state of not understanding. I tried to access a
> :lexical scoped variable from an outer routine:
> :  my($privat);
> ...
> :print $my_sub::privat;
> 
> Lexical variables are not in packages. 

Hello Tom!  

Your answer is placed above my question. Did you read further?

> You don't get more explanation so long as you have a screwed up
> address. 

I do not have a "screwed up address". I choose not to publish my
address in this group. Please respect this.

Perhaps you should say: "You don't get more explanation FROM ME so
long as you have a screwed up address".  Speak for yourself. 

> I'm glad this won't be allowed in the moderated group.

Some of your posts neither. This makes the situation no better, but I
think if you break rules you are in no good position to demand from
other persons to respect them. Or is this the same attitude that makes
you say "You don't get more explanation so long as you have a screwed
up address"?

Not related to this thread, but meant more globally: Thanks for the
effort you spent.

Followup set. Everyone should know when to stop. I will stop now.

regards
	Frank









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

Date: 27 Feb 1998 02:02:41 GMT
From: avm@best.com (avm)
Subject: Re: many ways but i can not find one
Message-Id: <avm-2602981801460001@avm.vip.best.com>

prompt% man perl | grep printf
                    printf "System returned %d\n", $retval;
       printf(FILEHANDLE LIST)
       printf(LIST)
       printf FILEHANDLE LIST
       printf LIST
               Equivalent to a "print FILEHANDLE  sprintf(LIST)".
                   s/\d+/sprintf("%5d",$&)/e;     # yields 'abc  246xyz'
       sprintf(FORMAT,LIST)
               Returns  a  string  formatted  by the usual printf
               pad or chop your value using sprintf().
       nonassoc  print printf exec system sort reverse
       in a printf or sprintf, it then  has  the  value  '*name',
       sprintf().




In article <34F5F7DF.7627@sonic.net>, star@sonic.net wrote:

> one newbe said to the other 
> "i be newbe 2"
> 
> I am what some call a newbe. i kinda like it! But I need help!-please-
> with formating.
> Here is my program i am trying to print out a column of strings indented
> by an amount the person inputs. 
> 
> #!/usr/bin/perl -w
> print "indent how much? ";
> $i=<stdin>;
> chomp $i;
> $y=$i;
> print "a list";
> chomp (@a=<STDIN>);
> foreach $x (@a)  {
>    printf "%/$y/)s\n", $x;
> }
> 
> i do not know printf (and can not find the man page)
> 
> Thanks,
> ~arthur Jacobs
> star@sonic.net


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

Date: Thu, 26 Feb 1998 19:15:12 -0800
From: ~arthur <star@sonic.net>
Subject: Re: many ways but i can not find one
Message-Id: <34F62FC0.2030@sonic.net>

Thanks avm,
 Now to figure that out!
~arthur

avm wrote:
> 
> prompt% man perl | grep printf
>                     printf "System returned %d\n", $retval;
>        printf(FILEHANDLE LIST)
>        printf(LIST)
>        printf FILEHANDLE LIST
>        printf LIST
>                Equivalent to a "print FILEHANDLE  sprintf(LIST)".
>                    s/\d+/sprintf("%5d",$&)/e;     # yields 'abc  246xyz'
>        sprintf(FORMAT,LIST)
>                Returns  a  string  formatted  by the usual printf
>                pad or chop your value using sprintf().
>        nonassoc  print printf exec system sort reverse
>        in a printf or sprintf, it then  has  the  value  '*name',
>        sprintf().
> 
> In article <34F5F7DF.7627@sonic.net>, star@sonic.net wrote:
> 
> > one newbe said to the other
> > "i be newbe 2"
> >
> > I am what some call a newbe. i kinda like it! But I need help!-please-
> > with formating.
> > Here is my program i am trying to print out a column of strings indented
> > by an amount the person inputs.
> >
> > #!/usr/bin/perl -w
> > print "indent how much? ";
> > $i=<stdin>;
> > chomp $i;
> > $y=$i;
> > print "a list";
> > chomp (@a=<STDIN>);
> > foreach $x (@a)  {
> >    printf "%/$y/)s\n", $x;
> > }
> >
> > i do not know printf (and can not find the man page)
> >
> > Thanks,
> > ~arthur Jacobs
> > star@sonic.net


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

Date: 27 Feb 1998 04:28:55 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: many ways but i can not find one
Message-Id: <6d5fe7$a2j$10@comdyn.comdyn.com.au>

In article <34F5F7DF.7627@sonic.net>,
	~arthur <star@sonic.net> writes:
> i do not know printf (and can not find the man page)

perldoc -f printf
perldoc -f sprintf

While you're at it:

perldoc perldoc
perldoc perl
perldoc perlfaq

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd.       | make a better idiot.
NSW, Australia                      | 


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

Date: Thu, 26 Feb 1998 19:44:43 -0800
From: "god.help" <mr.Nostrils@chronotope.com>
Subject: my first associative array
Message-Id: <34F636A9.3C6A3437@chronotope.com>

this is my first associative array.  i'd appreciate some help with
this.  the following sub while gives me $chick which is what I want.
the next sub counts works as well but i don't know how to retrieve
$chick for it.  how do i do it? filkins@condomania.com

sub while {
      if ($null =~ /$variable/) {
      $chick = "gal";
      } else {
      @track = ('a','b','c');
      $done = @track;
      $track2 = shift(@track);
      while ($done > 0) {
                   if ($variable =~ /$track2/) {
                          $trunk = $track2;
                           }
                   $done = $done - 1;
                   $track2 = shift(@track);
     }
     %set=("a","1","b","2","c","3");
     $chick = $set{"$trunk"};
}}



sub counts {

     unless (open (CLICK, "$chick")) {
          die ("cannot open file: $chick\n");
}
     $variable = <CLICK>;
     close (CLICK);

     unless (open (CLICK, ">$chick")) {
          die ("cannot open file: $chick\n");
}
     open (CLICK, ">$chick");
     print CLICK ($variable + 1);
     close (CLICK);
}







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

Date: Thu, 26 Feb 1998 12:53:41 -0500
From: John Porter <jdporter@min.net>
Subject: Perl Purify'd?
Message-Id: <34F5AC25.F57@min.net>

Q: has perl been Purify'd?  I sure hope so...

John Porter


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

Date: 27 Feb 98 02:48:48 GMT
From: "Deborah Murray" <dmurray@dgesolutions.com>
Subject: Perl Workshop
Message-Id: <01bd4323$760ece00$3398c9d0@debhome>

On-site training for Perl (Unix and Win32).
For more information, visit
http://www.uniforum.org/web/education/education2.hmtl



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

Date: Thu, 26 Feb 1998 18:31:03 -0800
From: amackey <amackey@tenforward.com>
Subject: Perl/CGI programmer needed.....
Message-Id: <34F62567.7971@tenforward.com>

I am in need of a proficient perl/cgi programmer willing to do some long
term contracted work.  Rates are negotiable.  

Aric
Angeles Computer Corp.


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

Date: Thu, 26 Feb 1998 20:43:21 -0800
From: William Jones <wbjones@msn.com>
Subject: problem installing Perl - Solaris x86
Message-Id: <34F64469.B5312A0@msn.com>

Hello,
  I am installing Perl on Solaris x86 v 2.6 using gcc v. 2.8.0.  I am
getting the error:

                 util.c 1569 : argument 'args' doesn't match prototype
                /usr/include/stdio.h:267: prototype declaration
                *** Error code 1
                make: Fatal error: Command failed for target 'util.o'

I've noticed that the offending type is a char* declaration for the
function vsprintf
By changing the type to __va_list, util.c compiles o.k., but, alas,
perlio.c runs into the same type issue.  I fear that modifying the
source isn't the correct route.  Should the compiler be searching in the
header files located at  /usr/include/? Or is there a non-default
command I should be setting in the Configure utility?

Any help would be appreciated


Bill



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

Date: 27 Feb 1998 07:54:40 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: removing new line (\n)
Message-Id: <6d5rg0$nb6$1@marina.cinenet.net>

Zylbersztejn Nathan (nathan@imagine.be) wrote:
: when I put the lines of a text in an @array how do i remove the "new
: line "(\n).

perldoc -f chomp

: s/\\n/ / doesn't work

Why would matching a literal backslash '\' followed by the letter 'n' be
expected to remove newlines?

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 26 Feb 1998 21:14:28 -0500
From: Grimoire <grimoire@oaktree.net>
Subject: Re: seeking and changing /etc/passwd
Message-Id: <Pine.LNX.3.95.980226210841.28416B-100000@harmony.oaktree.net>

On Thu, 26 Feb 1998, Peter Shankey wrote:

> how can I seek a particular user in /etc/passwd then change the second
> field from a "*" to a "!" when I only know the user's login name??
> 
> thanks
> pete
I'm not sure if this is the correct answer, but it might point you in the
right direction.  This code bit is not tested.


#!/usr/bin/perl -w

$pw = '/etc/passwd';
print "Login Name: ";
chomp($login = <STDIN>);
open(PW, $pw) || die "cannot open $pw: $!";
while(<PW>){
	if (/^$a/oi){
		($user, $pass, $uid, $null, $rn, $home, $shell) =
		split(/:/, $_);
		if($pass eq "*"){
			$pass = '!';
		}
	}
}




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

Date: 27 Feb 1998 04:03:21 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: seeking and changing /etc/passwd
Message-Id: <6d5du9$a2j$3@comdyn.comdyn.com.au>

In article <Pine.LNX.3.95.980226210841.28416B-100000@harmony.oaktree.net>,
	Grimoire <grimoire@oaktree.net> writes:
> I'm not sure if this is the correct answer, but it might point you in the
> right direction.  This code bit is not tested.

why not?

> #!/usr/bin/perl -w
> 
> $pw = '/etc/passwd';
> print "Login Name: ";
> chomp($login = <STDIN>);
> open(PW, $pw) || die "cannot open $pw: $!";
> while(<PW>){
> 	if (/^$a/oi){

This probably should be $login.

What happens if you have three users like this:

foobar:
foobarbaz:
FOObar:

All three of them would be matched if I asked for user foobar, or even
foo.

You're not writing the results back to the passwd file, which was the
original question. In this case, that's good. You should never modify
that file in this way. It should be proerly locked.

bottom line: Do not modify this sort of stuff unless you really know
what you're doing.

Martien
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Webmaster www.tradingpost.com.au    | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: 27 Feb 1998 04:05:12 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: seeking and changing /etc/passwd
Message-Id: <6d5e1o$a2j$4@comdyn.comdyn.com.au>

In article <34F60AE5.F4996301@charlestoncounty.org>,
	Peter Shankey <shankeyp@charlestoncounty.org> writes:
> how can I seek a particular user in /etc/passwd then change the second
> field from a "*" to a "!" when I only know the user's login name??

See my other posts in this thread, and some post that I sent in reply
to someone else wanting to modify their password files like this.

In short: if you have to ask how, then you should not even contemplate
doing it. There are too many issues involved.

Martien

PS. use www.dejanews.com to find previous answers to this question.
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Webmaster www.tradingpost.com.au    | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: 27 Feb 1998 03:59:08 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: seeking and changing /etc/passwd
Message-Id: <6d5dmc$a2j$2@comdyn.comdyn.com.au>

In article <6d55gh$iqj$1@ha2.rdc1.sfba.home.com>,
	dmmartin@home.net (Michael Martin) writes:

> $username = "foobar";
> 
> open(PASSWD, "+</etc/passwd");

You're not checking the return code from open().

> while(<PASSWD>){
> s/^$username:\*:/^$username:!:/;

This just changes the contents of $_. You are not writing the result
back to /etc/passwd.

The ^ in the replacement pattern is a literal ^. That means that the
username will be replaced by the username with a ^ in front of it.

> last;

You really only want to look at the first line?

> }
> __END__

Did you test this?

> that snipit should work, although it is untested...  Basicly it

Nope, it shouldn't.

> loops through your shadowed password file and looks for the exact
> username you specified.  When it finds it, the script replaces the
> username and the * with the username and a !.

Even if your code worked, what happens if another process is writing
to the same file at the same time? I mean, passwd files can be changed
by a ton of processes.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd.       | thing but mean your mother.
NSW, Australia                      | 


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

Date: 27 Feb 1998 05:57:02 GMT
From: "jim babbington" <jwb79@mail.idt.net>
Subject: Re: sending text to command line
Message-Id: <01bd4343$be765da0$6488fdc7@dixon>


>  If I have the command string stored in "$modify"
> how can I execute it?  I have tried exec("$modify") and variations on
this -

Have you tried system($modify) ... or  if you want to test/store the output
from the
command, try:

$command_output = qx($modify)    # the "(" will be subsitued by perl with `
(execute quote)

Good luck,
Jim




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

Date: Thu, 26 Feb 1998 22:37:06 -0500
From: Dan Boorstein <danboo@negia.net>
Subject: stumper: fun with perl
Message-Id: <34F634E2.81DA055C@negia.net>

hello all,

i have come across some odd behavior, and i thought it might be fun to
share it as a stumper. to some it may be obvious. if so, my apologies
for wasting your time, but please refrain from answering until others
have toiled a bit. furthermore, there may be many answers of which
i am not aware. if so, i'll learn something. regardless, here you go.
sorry, there are no prizes aside from personal satisfaction.

<MUSIC SRC="syncopated_clock.mp3" ALT="Jeopardy">

   summary: write a script which prints "foo\n" when run interactively
            but "bar\n" when run from a file.

   details: we're all aware that you can run perl interactively by
            directly executing the interpreter. additionally we could
            store the statements in a file, and pass it as an argument
            to the interpreter.

            the idea is to come up with a script which will behave in
            a different manner depending on whether it is run from
            a file or interactively. now i realize this end result
            is quite nebulous, so let me define the goals precisely.

            your script must print "foo\n" and only "foo\n" when run
            interactively and must print "bar\n" and only "bar\n" when
            run from a file. the text of your scripts must be the same.

            here's one way to do it by refering to the filename. this
            seemed obvious so it is outlawed (see below).

            interactively:
              prompt> /usr/bin/perl
              print $0 eq '-' ? 'foo' : 'bar';
              print "\n";
              ^D
              foo

            from a file:
              prompt> cat foobar.pl
              print $0 eq '-' ? 'foo' : 'bar';
              print "\n";
              prompt> /usr/bin/perl foobar.pl
              bar

qualifiers: 1. the same perl interpreter must be used for both trials.
            2. no command-line switches, parameters or arguments may be
               used aside from the script name.
            3. the script cannot refer to its own filename through $0,
               __FILE__ or other methods (that would be too easy).
            4. the script may not reference external sources including,
               but not limited to, modules, libraries, databases or
               shell commands.
            5. the script must assume that its environment is identical
               between trials, aside from the manner in which it is
               invoked of course.
            6. and most importantly, have fun. :)

</MUSIC>

good luck,

-- 
dan boorstein


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

Date: 27 Feb 1998 02:00:38 -0600
From: psamuels@sampo.REMOVETHIS.creighton.edu (Peter Samuelson)
Subject: Re: The Ineffable Tom C.
Message-Id: <6d5rr6$kes$1@sampo.creighton.edu>

[Sean Ahern <SxA@wrdcom.clara.net>]
> Since, of course, every damn person on this group who thinks it's
> forgivable to insult beginners for asking 'obvious' questions has
> never, ever done the same thing in their past.

I hope you don't think you're exaggerating for shock value or whatever.
You aren't.  A number of us have come to that precise conclusion.
Trying to learn a *programming language* without reading any
documentation is *stupid*.  Trying to get someone to volunteer time
helping you learn a programming language without reading any
documentation is *rude*.  I see no need to be overly polite to such
people.

And no.  I have never, ever done the same thing in my past.  I assume
with some confidence that Tom and several others here can say the same.

There is not, repeat, *not* a danger of scaring away potential Perl
programmers/developers.  Few "stupid people" as I define above are in
any danger of becoming effective Perl users (or programmers of other
languages, for that matter) any time soon.  I think it's an aptitude
thing.  Nor do we lose advocates: those who can't program are really in
no position to form independent, informed opinions (good or bad) of the
language anyway; thus as advocates (or detractors) their opinions are
effectively useless.

-- 
Peter Samuelson
<sampo.creighton.edu ! psamuels>


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

Date: 27 Feb 1998 04:08:47 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Two questions about POD
Message-Id: <6d5e8f$a2j$5@comdyn.comdyn.com.au>

In article <Ep0HCt.J6r@rna.nl>,
	Gerben_Wierda@RnA.nl writes:

> I am running 5.004.04

5.004_04? Same as I am testing it with.

>>=head1 DIAGNOSTICS
>>
>>=over 4
>>
>>=item Usage: gord_use.pl [--verbose=i] [--user=s] (active|inactive|test)
> 
> I get
> 
>>DIAGNOSTICS
>>(active|inactive|test)
>>     Usage: gord_use.pl [--verbose=i] [--user=s]

I don't.

% cat a.pod
=head1 DIAGNOSTICS

=over 4

=item Usage: gord_use.pl [--verbose=i] [--user=s] (active|inactive|test)
% pod2text a.pod
DIAGNOSTICS
    Usage: gord_use.pl [--verbose=i] [--user=s] (active|inactive|test)
%

-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd.       | clothes.
NSW, Australia                      | 


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

Date: 26 Feb 1998 21:12:24 -0500
From: Justin Vallon <vallon@pearl.fi.bear.com>
Subject: Re: use system or backticks??
Message-Id: <x6elnuxn6d3.fsf@pearl.fi.bear.com>

mgjv@comdyn.com.au (Martien Verbruggen) writes:

> In article <mshavel-2502982036310001@130.9.16.207>,
> 	mshavel@erols.com (Michael Shavel) writes:
> 
> > My question is, should I be using something like "system" to call this
> > statement or are the backticks the way to go. Also could someone please
> 
> Depends. Do you need the output from the command? Then use backticks.
> Do you need the return value, use system.

You can get the return status of a backtick with $?:

local $txt = `ls`;
die "ls failed (status $?)" if $?;

-- 
-Justin
vallon@bear.com


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

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

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