[17586] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5006 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 1 06:05:31 2000

Date: Fri, 1 Dec 2000 03:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975668709-v9-i5006@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 1 Dec 2000     Volume: 9 Number: 5006

Today's topics:
    Re: Anybody know what the carriage control characters a <mjcarman@home.com>
    Re: Calling Perl from Perl??? (Rafael Garcia-Suarez)
        flock under Solaris behaves strangely <ronald_f@my-deja.com>
    Re: Help needed: how to get information (path) where Pe <mjcarman@home.com>
    Re: Help! (Abigail)
    Re: Looping problem <ronald_f@my-deja.com>
    Re: Pearl HELP, How to? <johngros@Spam.bigpond.net.au>
    Re: Perl string converter (Abigail)
    Re: Random password generator simbean@my-deja.com
        reading from <STDIN> with sysread?? simbean@my-deja.com
    Re: reformatting a perl script <nospam.newton@gmx.li>
    Re: reformatting a perl script <nospam.newton@gmx.li>
    Re: reformatting a perl script <nospam.newton@gmx.li>
    Re: reformatting a perl script <bart.lateur@skynet.be>
    Re: Regex to replace double-returns with <P> <bart.lateur@skynet.be>
    Re: Regexp q (Bernard El-Hagin)
        Space near the middle <bart.lateur@skynet.be>
    Re: Space near the middle <jeffp@crusoe.net>
    Re: txt files getting denied. <mjcarman@home.com>
    Re: Using goto (Abigail)
        why could't i do something like this? <mantisman@usa.net>
    Re: why could't i do something like this? (Rafael Garcia-Suarez)
    Re: why could't i do something like this? simbean@my-deja.com
    Re: why could't i do something like this? <mantisman@usa.net>
    Re: why could't i do something like this? <johngros@Spam.bigpond.net.au>
    Re: why could't i do something like this? <johngros@Spam.bigpond.net.au>
    Re: why could't i do something like this? <mantisman@usa.net>
    Re: Why? <mjcarman@home.com>
    Re: Why? (Bernard El-Hagin)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 30 Nov 2000 09:27:42 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Anybody know what the carriage control characters are ?
Message-Id: <3A2671EE.F2FF5D64@home.com>

Jack Altradmon wrote:
> 
> I have a 'real-time' counter which shows number of files being
> processed.
> 
> Before I print out the updated counter I print out a number of '\ch'
> characters which backspaces the cursor. What are the special
> characters for moving the cursor to beginning of line, 
> end of line, forward spacing..?

I don't know all of those, (and I don't think that a "move to end of
line" char even exists) but backspace is "\b" in Perl, and you can use 
"\f" (formfeed) to return to the beginning of the current line.

-mjc


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

Date: Fri, 01 Dec 2000 08:25:24 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Calling Perl from Perl???
Message-Id: <slrn92eo54.gp3.rgarciasuarez@rafael.kazibao.net>

ilwilson@frontiernet.net wrote in comp.lang.perl.misc:
> I have a Perl password maintenance script in Unix, which is controlled
> online via HTML calls. The script is abviously called using something
> like myscript.cgi?USER=username&PASSWORD=password ..... etc.  I would
> also like to call the script from the Unix prompt as well as from HTML,
> but with as little code-changing as possible.

If your script uses CGI.pm, it's already able to be called from the
command-line. See the documentation for CGI.pm, section "debugging".

> Is there a simple method of calling the script from the command-line so
> that I can still retrieve the info using the standard "read_input"
> routine, via the ENV variables?  ie. Different manner of calling, but
> same method of retrieval.

There is no such thing as a standard read_input routine. Apparently your
script doesn't use CGI.pm. Too bad.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 01 Dec 2000 09:33:41 GMT
From: Ronny <ronald_f@my-deja.com>
Subject: flock under Solaris behaves strangely
Message-Id: <907r9m$q6v$1@nnrp1.deja.com>

Before I'm completely going nuts, maybe someone could point out what I'm
doing wrong here. I want to implement the following logic:

lock file exclusive and non-blocking;
if locking succeeds
   process file
else
   print error message

This is a stripped-down version of what I have:

use Fcntl qw(:DEFAULT :flock);
open(X,">>x") or die;
my $fl=flock(X,LOCK_EX+LOCK_NB);
unless ($fl)
{
    print "flock failed: $fl\n";
}
else
{
    sleep (40); # simulate usage of file
    close X; # also removes lock
}

Strangely, it never goes to 'flock failed'. For instance, when I start
this program in one xterm window and, while it sleeps, start another
copy in another window, flock returns 0 in *both* cases.

What could be the reason? If there is a better way to implement it,
please let me know.

Ronald
--
Ronald Fischer <ronald_f@my-deja.com>
http://profiles.yahoo.com/ronny_fischer/


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


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

Date: Thu, 30 Nov 2000 08:35:57 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Help needed: how to get information (path) where Perl script is  located?
Message-Id: <3A2665CD.57DED0A2@home.com>

Alain BARBET wrote:
> 
> DS wrote:
> 
> > I need that information during runtime. Running Perl under Win98.
>
> One method:
> #!/usr/bin/perl
> use CGI qw/:standard :html3 :netscape escape unescape/;
> use CGI::Carp qw/fatalsToBrowser/;

When did the OP say anything about CGI?

> print header,`pwd`;

You need to read more closely. The OP said he was on Win98. 'pwd' is a
*nix command.
 
> Another, more clean (without system call).
> #!/usr/bin/perl
> use CGI qw/:standard :html3 :netscape escape unescape/;
> use CGI::Carp qw/fatalsToBrowser/;
> use Cwd;
> print header,cwd;

Again, no mention of CGI, but the Cwd module may help him. He should
also look at the FindBin module.

-mjc


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

Date: 1 Dec 2000 09:34:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Help!
Message-Id: <slrn92es5s.bha.abigail@tsathoggua.rlyeh.net>

On Thu, 30 Nov 2000 22:38:42 -0500, Diana Richardson (dfryberg@kent.edu) wrote in comp.lang.perl.misc <URL: news:<90788c$huv$1@usenet.kent.edu>>:
++ I am totally at my wits end and I know you don't really like helping with
++ homework but I'm stuck. I've tried every combination I know and I keep
++ getting error messages I can't find in any book. The professor is so bad
++ when you ask for an explanation he just confuses you more. Well I won't even
++ go there.
++ 
++ I need to write a program that will create this pattern:
++ 
++ aba, abba, abbba, etc.
++ 
++ Simple right? HaHaHaHaHa

    perl -le '$_ = aa; print while s/a/ab/'

++ 
++ Well this is what I've done in many variations, I'll just give you the
++ latest because I actually get the same error with every change:
++ 
++ #!/usr/bin/perl -w
++ 
++ $firstpart = ab
++ $addb = +b
++ $lastpart = a
++ 
++ print ($firstpart . $addb + $lastpart);
++ 
++ This is my error message:
++ 
++ Unquoted string "a" may clash with future reserved word at abba line 7.
++ syntax error at abba line 7, near "a
++ 
++ print"
++ Execution of abba aborted due to compilation errors.


Well, you aren't quoting the strings, so Perl issues a warning. Putting
quotes around them helps. Then, statements need to be separated by 
semicolons; you are missing a few. In the print statement, you have
both `.' and a `+'. I wonder why. Finally, you only have one print
statement, and no looping construct. How do you plan to print more
than once?



Abigail


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

Date: Fri, 01 Dec 2000 09:41:29 GMT
From: Ronny <ronald_f@my-deja.com>
Subject: Re: Looping problem
Message-Id: <907ro8$qit$1@nnrp1.deja.com>

In article <liIV5.1061$L27.463137@dfiatx1-snr1.gtei.net>,
  "res06xbi" <res06xbi@gte.net> wrote:
> @tables = open(FILE1, "sorted_name.lis");

open does not return the content of the file, but a status indicating if
the open worked or not. To get the content in one gulp, you could use

@tables = <FILE1>;
--
Ronald Fischer <ronald_f@my-deja.com>
http://profiles.yahoo.com/ronny_fischer/


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


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

Date: Fri, 01 Dec 2000 10:27:33 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Pearl HELP, How to?
Message-Id: <p2LV5.508$xW4.3115@news-server.bigpond.net.au>

open (FRAME,"links.pl");
You should use explicit paths to avoid problems with file location.
"MrBafner" <mrbafner@dexrix.NS.com> wrote in message
news:3a275015$0$19410$7f31c96c@news01.syd.optusnet.com.au...
> change this so it opens "links.pl" instead of referring to "site/frame"
>
> open (FRAME,"sites/frame");
> while($line=<FRAME>)
> {print "$line";}
> close(FRAME);
> exit;
>
>  }
>
> }
> close(USER);
> print "Content-Type: text/html\n\n";
> open (FRAME,"sites/frame");
> while($line=<FRAME>)
> {print "$line";}
> close(FRAME);
>
> }
>
>
>
>
>




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

Date: 1 Dec 2000 10:22:49 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl string converter
Message-Id: <slrn92euvp.bha.abigail@tsathoggua.rlyeh.net>

On Fri, 01 Dec 2000 04:34:52 GMT, Bob Walton (bwalton@rochester.rr.com) wrote in comp.lang.perl.misc <URL: news:<3A272B18.56A2F095@rochester.rr.com>>:
++ designpixs@my-deja.com wrote:
++ > 
++ > I want to be able to pass in a string of any size
++ > and return an integer.  The return value is
++ > always unique to the string passed in.  (i.e.
++ > pass in TEST returns 3452, pass in TESTS returns
++ > 234532) The return value MUST be a unique value
++ > to the value passed in.  If I pass in TEST and
++ > get 1234 and the later pass in TEST I should get
++ > 1234.
++ ...
++ > Drew
++ ...
++ What you're asking for is technically infeasible.  There are a *lot* of
++ strings "of any size" out there, and only a relative handful of integer
++ values.  For example, a 100000-character string has 2**800000 possible
++ values (which is probably more than the number of electrons in the
++ universe), while a standard integer has only 2**32 possible values.  I
++ suppose you could use the Math::BigInt package to represent a unique
++ number for each such string, but then why not just use the string
++ itself, since there would be a 1:1 relationship anyway?

Well, 18457123481273012315713645734592745983749171023827156175619 is a
perfectly valid integer. Perl might not be able to do arithmetic with
it, but it doesn't have a problem storing it in a scalar.

Here's a trivial function that uniquely maps any string to an integer:

    sub str2int {join "" => map {sprintf "%03d" => ord} split // => shift}



Abigail


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

Date: Fri, 01 Dec 2000 09:07:43 GMT
From: simbean@my-deja.com
Subject: Re: Random password generator
Message-Id: <907pos$p94$1@nnrp1.deja.com>

In article <9078fv$c6h$1@nnrp1.deja.com>,
  fallenang3l@my-deja.com wrote:
> I am looking for a random password generator (don't bother with
> Crypt::RandPasswd because sometimes it can be painstainklingly [sp?]
> slow). It doesn't have to be really complicated, just pretty random.

I wrote a password generator once.
Please don't tell me that it is ugly or slow, because I know it is for
I am still learning. But I would appreciate advice about how to create
better [cleaner] code. :)

Ok, here we go:


my @all =
('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', '
E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S'
, 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v
', 'w', 'x', 'y', 'z');
srand (time | $$);
my $p, $z, $value;

while(length($p)<6)
{
   $p = "";
   $z = 0;
   while($z<6)
   {
      $value = int (rand(64));
      $p .= $all[$wert];
      $z++;
   }
}
return $p;


Hope that helps :)

Ciao,
SimBean


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


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

Date: Fri, 01 Dec 2000 08:45:29 GMT
From: simbean@my-deja.com
Subject: reading from <STDIN> with sysread??
Message-Id: <907of8$o86$1@nnrp1.deja.com>


> Put STDIN into non-blocking mode...
> use Fcntl;
> fcntl(STDIN,F_SETFL,O_NONBLOCK);
>
> ...and then use sysread().
Isn't sysread() non-blocking anyway?
I tried to use sysread before and created a handle to <STDIN>. When I
then read from the handle(one byte per time), sysread didn't return
anything, but output wasn't undef either.
What would the code look like if I wanted to use sysread? Are there any
examples out there?
Sorry for my stupid questions, but I really don't know what I am doing
wrong!

Thank you,
Simbean.


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


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

Date: Fri, 01 Dec 2000 10:49:28 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: reformatting a perl script
Message-Id: <7ase2tgs5ofv9p179351ma29s57jt0lv2s@4ax.com>

On Thu, 30 Nov 2000 18:21:01 -0500, tadmc@metronet.com (Tad McClellan) wrote:

> A Cabal needs a secret handshake.
> 
> Answer 20 clpmisc questions

Correctly? Or is cargo-cult and wrong OK? :-)

> , write 2 modules, and say 5 Hail Larry's, then we'll talk...

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.


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

Date: Fri, 01 Dec 2000 10:49:29 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: reformatting a perl script
Message-Id: <ldse2t819alsu32jkvv0mau7k10ggn37on@4ax.com>

On Fri, 01 Dec 2000 00:58:27 GMT, Bart Lateur <bart.lateur@skynet.be> wrote:

> 	B::Deparse
> 
> or is that O::Deparse?

B::Deparse, but usually invoked through the O module via -MO=Deparse.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.


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

Date: Fri, 01 Dec 2000 10:49:29 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: reformatting a perl script
Message-Id: <hese2tsqdb3ch1fbm6mjtrqk81t2cq7tak@4ax.com>

On Thu, 30 Nov 2000 14:01:00 -0800, Ken <ka@pacific.net> wrote:

> Can you point me to some docs on this, or can you tell me the proper
> command line switches to tell it to leave comments in and to parse the
> whole script, not just the main section?

B::Deparse can't "leave comments in" since it never sees them, as far as I
understand it. After all, they're not stored with the compiled opcodes that I
believe B::Deparse, um, deparses. (By a similar token, it can't "leave multiple
newlines intact", since it doesn't see any of the original formatting.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.


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

Date: Fri, 01 Dec 2000 10:19:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: reformatting a perl script
Message-Id: <pnue2t0788sln1412cgct6dfnc3n5nrcq1@4ax.com>

Philip 'Yes, that's my address' Newton wrote:

>B::Deparse, but usually invoked through the O module via -MO=Deparse.

As an aside: what's the trick? How come the script if never run, if
invoked with an O::* module?

-- 
	Bart.


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

Date: Fri, 01 Dec 2000 10:21:22 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regex to replace double-returns with <P>
Message-Id: <esue2tomf78q6g7v06eq9cvl7bs9acmu2g@4ax.com>

Philip Obbard wrote:

>Your response got me thinking in a different direction, and it WORKS!
>
>$media_copy =~ s/\012\015/<P>/g;

Note that is one CRLF pair, not two newlines in a row.

Gezt rid of *any* cr's before you proceed.

	tr/\r//d;

Now, your original idea should work:

	s/\n\n/\n<P>/g;

-- 
	Bart.


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

Date: Fri, 1 Dec 2000 08:26:29 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Regexp q
Message-Id: <slrn92entt.cag.bernard.el-hagin@gdndev25.lido-tech>

On Thu, 30 Nov 2000 10:12:16 -0500, Tad McClellan <tadmc@metronet.com>
wrote:
>Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>
>>Try setting the variable $/ to an empty value (perldoc perlvar for more
>>info on this variable):
>>
>
>>$/ = '';
>
>
>That would not work with:
>
>------------------------
>/* a comment with
>
>   a blank line in it */
>------------------------

If someone writes comments that way they desreve to have their regexes
break on them. :-)

But you are, of course, quite correct. I just made the assumption that
people don't comment that way. And everybody knows that when one makes an
assumption one makes an ass out of umption...or something like that.

Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'


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

Date: Fri, 01 Dec 2000 09:40:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Space near the middle
Message-Id: <6nre2tgr32ut5984r6ofsa3fdh12e1odn5@4ax.com>

Here's a cute little stomper.

I have a bunch of strings, which are too long to fit on one line. So
they must be split on a space into two parts, to be printed onto two
lines. In order to look nice (subjective, that), I thought it'd be best
if both halves both look well balanced, thus, of similar length.

So, a phrase like

	external diameter in mm

should rather be split as 

	   external
	diameter in mm

not as 

	external diameter
	      in mm


Question: is there a neat way to find that splitting point (a space)
near the middle of the string? Can it be done with regexes?

-- 
	Bart.


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

Date: Fri, 1 Dec 2000 05:22:57 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Space near the middle
Message-Id: <Pine.GSO.4.21.0012010452190.5826-100000@crusoe.crusoe.net>

On Dec 1, Bart Lateur said:

>So, a phrase like
>
>	external diameter in mm
>
>should rather be split as 
>
>	   external
>	diameter in mm
>
>not as 
>
>	external diameter
>	      in mm
>
>
>Question: is there a neat way to find that splitting point (a space)
>near the middle of the string? Can it be done with regexes?

  my $string = "external diameter in mm";
  my $half  = int(length($string)/2);

  $string =~ s/( ?)([^ ]*)(?<=^.{$half})([^ ]*)( ?)/
    length($2) < length($3) ? "\n$2$3$4" : "$1$2$3\n"
  /e;

  print $string;
  
-- 
Jeff "japhy" Pinyan     japhy@pobox.com    http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource  (my id:  PINYAN)       http://search.cpan.org/
PerlMonks - An Online Perl Community          http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc.   http://www.perlarchive.com/








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

Date: Thu, 30 Nov 2000 09:15:55 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: txt files getting denied.
Message-Id: <3A266F2B.5F03F7A7@home.com>

[Jeapordectomy performed. Posting upside down has been found to
correlate directly to the level of cluelessness of the poster.]

Ed Grosvenor wrote:
> 
> John Boy Walton wrote:
>
> > I created some text files and ran a script against them and I keep
> > getting permission denied. Here is the script.
>
> >  #!e:/millenium programs/perl/bin/perl

No -w? :(

> >  use strict;

Good! :)

> >  my $path = "C:/Program Files/G6FTP/";
> >  my $datapath = "C:/Program Files/G6FTP/ftpdatabase/";
> >  my $name = "";
> >  opendir DIR, $datapath;

Add a check for success here.

> >  my $file = $path."Users.ini";
> >  open (USERS, "+>$file");

And another one here.

> >  while ( defined( $name = readdir DIR ) )
> >  {
> >   chomp ($name);
> >   $file = $datapath.$name;
> >   open BOGUS,">>$file" or die "Unopened because $!";
> >   my $pass = <BOGUS>;

You just opened a file in append mode (or tried to) and then tried to
read a line from it. You can't do that. Change your open() to this:

open BOGUS, "< $file" or die "Couldn't open '$file' because: $!";

> >  $name =~ s/.txt//;
> >   my $value = "[".$name."]\nLogin=".$name."\n"."Pass=".$pass."\n\n";
> >                    print USERS $value;
> >                    unlink $file;

unlink() can fail too, you should probably check its return value.

> >       close BOGUS;
> >
> > }
> > closedir DIR;
> > close USERS;
> > I have made no permission changes to them yet they stopped 
> > being accessible to my scripts. Does anyone know what I did 
> > to trigger this?
>
> In Windows, the easiest way to get a Permission Denied error is 
> to try to create a file that already exists.

Who said anything about creating files?

> It looks like that's what you might be doing.  Try deleting the file
> c:\Program Files\G6FTP\Users.ini and then running the program.  
> I'll bet it'll work.  

I'll bet it won't. Given that he wants to open that file for read/write,
I'd say that deleting it might make it difficult to do the read part.

> See, you're telling it to create that file with Read/Write access
> (+>).  If that file already exists (and it probably does), then it
> won't be able to create it.

Go read the manpage for open() before spouting off crap like this.
open() does *not* create a new file every time you use it. It opens a
file in the specified mode. *If* you try to open a file for writing,
*and* it doesn't exist already, *then* it will be created. (OS willing)

> So if you just want to open it with write access, use > where 
> you're using +>.

'+>' is a perfectly valid mode to open a file in, if a little odd. It
says "open this file for both reading and writing, and clobber the file
first." If the OP truly needs both read/write access, he should change
the '+>' to '+<' -- but that is a seperate issue from his permissions
problem.

More importantly, he doesn't have a diagnostic on the open() with '+>'
mode, so that's not the one he's getting the error on! He must be
getting the error on the one place where he actually does (properly)
check for success:

> >   open BOGUS,">>$file" or die "Unopened because $!";

I've already commented on that. I think he wants to open in read mode.

> Other than that, I can't think of anything in your script that 
> would cause that error.

That's because the error isn't "in" the script. "Permission Denied"
means that the OS won't let you do what you just asked to. In this case,
open a file in append mode. Now, why would that happen? Because the user
doesn't have write permissions to the file. John, do you *want* to write
to those files? If so, check if they're flagged read-only.

At any rate, John, you don't seem to have a good grasp specifying file
modes with open(). Study the open() manpage (perldoc -f open) to get a
better understanding.

-mjc


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

Date: 1 Dec 2000 11:03:12 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Using goto
Message-Id: <slrn92f1bg.bha.abigail@tsathoggua.rlyeh.net>

On Fri, 01 Dec 2000 08:00:52 GMT, Shawn Smith (SPAM_loginprompt@yahoo.com) wrote in comp.lang.perl.misc <URL: news:<3a275831.1941907@netnews.worldnet.att.net>>:
++ Hello all,
++ 
++ I am fresh out of school w/ a dream job. I am to improve some perl
++ code. I am very new to perl too, but love it a lot. I have the camel
++ and the cook book.
++ 
++ Some of the scripts have goto statements. What I have read is that
++ goto's slow down the scripts because goto's cause Perl to compile the
++ scripts on every run. I thought that the scripts got interpreted. Can
++ someone explain this or direct me to the proper docs?

Perl programs get compiled each time you run it. The fact there are gotos
in it is irrelevant.

++ Also, to justify removing the goto's I must show that it will improve
++ the efficiency of the scripts. I can't just say hey these are not
++ cool. The goto's are (so far, I have only read 3 of a dozen scripts)
++ being used when an error occurs. Thus, only on rare occasions do the
++ goto's get used.


If gotos are only used on rare occasions, they can't have much influence
on efficiency, can they? To increase the performance, one focusses on
the bottlenecks, on one some error handling code that isn't called often.

Gotos can, in some cases, be useful. Just as sometimes you don't want
to use strict or warnings.



Abigail


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

Date: Fri, 1 Dec 2000 17:28:12 +0800
From: "Joe" <mantisman@usa.net>
Subject: why could't i do something like this?
Message-Id: <907r86$li7$1@imsp026.netvigator.com>

#here below is a chunk of code

if ( for (@links){
 $base = 'http://www.quamnet.com/fcgi-bin/c/';
 $k = $base . $_;
 $content[$i] = $quamnet ->FetchURL($k);
 $i = $i + 1;
}){
 print "ok for retrieving files";
}
else{
 print "there is a problem : $!";
}

#and error messages are below

#syntax error at C:\PERL\BIN\A line 9, near "( for "
#syntax error at C:\PERL\BIN\A line 14, near "}"
#Execution of C:\PERL\BIN\A aborted due to compilation errors.





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

Date: Fri, 01 Dec 2000 09:45:01 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: why could't i do something like this?
Message-Id: <slrn92esqd.h2a.rgarciasuarez@rafael.kazibao.net>

Joe wrote in comp.lang.perl.misc:
> #here below is a chunk of code
> 
> if ( for (@links){
>  $base = 'http://www.quamnet.com/fcgi-bin/c/';
>  $k = $base . $_;
>  $content[$i] = $quamnet ->FetchURL($k);
>  $i = $i + 1;
> }){
>  print "ok for retrieving files";
> }
> else{
>  print "there is a problem : $!";
> }

I can't even imagine what behavior you expect from this code. How do you
want to define the truth value of a for loop?

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 01 Dec 2000 10:05:34 GMT
From: simbean@my-deja.com
Subject: Re: why could't i do something like this?
Message-Id: <907t5d$re1$1@nnrp1.deja.com>



> if ( for (@links){
>  $base = 'http://www.quamnet.com/fcgi-bin/c/';
>  $k = $base . $_;
>  $content[$i] = $quamnet ->FetchURL($k);
>  $i = $i + 1;
> }){
>  print "ok for retrieving files";
> }
> else{
>  print "there is a problem : $!";
> }
I think the problem is, that you don't get a boolean from the statement
in the if-braces.

Just a thought ... ;)


Ciao,
SimBean.


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


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

Date: Fri, 1 Dec 2000 18:18:50 +0800
From: "Joe" <mantisman@usa.net>
Subject: Re: why could't i do something like this?
Message-Id: <907u74$82$1@imsp026.netvigator.com>

sorry guys for i asked a silly question

<simbean@my-deja.com> ¼¶¼g©ó¶l¥ó news:907t5d$re1$1@nnrp1.deja.com...
>
>
> > if ( for (@links){
> >  $base = 'http://www.quamnet.com/fcgi-bin/c/';
> >  $k = $base . $_;
> >  $content[$i] = $quamnet ->FetchURL($k);
> >  $i = $i + 1;
> > }){
> >  print "ok for retrieving files";
> > }
> > else{
> >  print "there is a problem : $!";
> > }
> I think the problem is, that you don't get a boolean from the statement
> in the if-braces.
>
> Just a thought ... ;)
>
>
> Ciao,
> SimBean.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Fri, 01 Dec 2000 10:38:32 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: why could't i do something like this?
Message-Id: <IcLV5.517$xW4.3508@news-server.bigpond.net.au>

I made some changes I think would give you what you want. Hope it helps.
"Joe" <mantisman@usa.net> wrote in message
news:907r86$li7$1@imsp026.netvigator.com...
> #here below is a chunk of code
>
for (@links){
>  $base = 'http://www.quamnet.com/fcgi-bin/c/';
>  $k = $base . $_;
>  $content[$i] = $quamnet ->FetchURL($k) or &problem;
>  $i = $i + 1;
> }
exit;
sub problem;
print "can't retrieve $k : $!";
return;





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

Date: Fri, 01 Dec 2000 10:47:22 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: why could't i do something like this?
Message-Id: <_kLV5.528$xW4.3446@news-server.bigpond.net.au>

Sorry the sub problem; should be followed by{
and the line after return; should be }

> for (@links){
> >  $base = 'http://www.quamnet.com/fcgi-bin/c/';
> >  $k = $base . $_;
> >  $content[$i] = $quamnet ->FetchURL($k) or &problem;
> >  $i = $i + 1;
> > }
> exit;
> sub problem;
> print "can't retrieve $k : $!";
> return;
>
>
>




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

Date: Fri, 1 Dec 2000 18:44:07 +0800
From: "Joe" <mantisman@usa.net>
Subject: Re: why could't i do something like this?
Message-Id: <907vmh$4c8$1@imsp026.netvigator.com>

i made it and thx a lot

"John Boy Walton" <johngros@Spam.bigpond.net.au> ¼¶¼g©ó¶l¥ó
news:_kLV5.528$xW4.3446@news-server.bigpond.net.au...
> Sorry the sub problem; should be followed by{
> and the line after return; should be }
>
> > for (@links){
> > >  $base = 'http://www.quamnet.com/fcgi-bin/c/';
> > >  $k = $base . $_;
> > >  $content[$i] = $quamnet ->FetchURL($k) or &problem;
> > >  $i = $i + 1;
> > > }
> > exit;
> > sub problem;
> > print "can't retrieve $k : $!";
> > return;
> >
> >
> >
>
>




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

Date: Thu, 30 Nov 2000 08:27:48 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Why?
Message-Id: <3A2663E4.F5E6EF96@home.com>

Ed Grosvenor wrote:
> 
> I have an idea. For those of you who insist on tearing someone a
> new orifice whenever they fail to read the Perl docs, why don't 
> you print up a copy of the Perl docs and publish a phone number 
> that these poor newbies can call to get a copy.

Oh, boy. For your sake, Ed, I hope that this is far enough down in a
thread that it escapes much attention; because if it doesn't, I think
that you're about to get "a new orifice" yourself.

There's no need for anyone here to print up a hardcopy of the
documentation and start mailing it to newbies on request. If you have
Perl on your computer, you have the documentation too. It's part of the
distribution. Go to your command line and type 'perldoc perl' See that?
Isn't it cool? All the docs right there at your fingertips!

Okay, in fairness, I don't know how Mac users get at the docs, and there
could be a few relatively obscure OS's without perldoc, but for
everybody else out there, there aren't any excuses.

If (for some bizarre reason) you don't have the docs on your computer,
you can always go to www.perldoc.com or www.activestate.com to view them
on the web. You can download them from CPAN.

> [...] when it comes down to it, those docs are not only 
> convoluted and difficult for some to read,

If you feel that way, perhaps you could offer suggestions to improve
their clarity. For myself, I think the docs are pretty well written. At
any rate, if a person *does* read the docs and you still doesn't
understand something, the people here are more than happy to help. We
just want you to try to figure things out on your own first.

> but they're [the docs] also about as exciting as your great
> grandmother's denture story every Thanksgiving.

So your short attention span is justifies you asking a question to the
whole world when you could easily find the answer yourself? I don't
think you'll find much sympathy with that argument.

> Secondly, I'm pretty sure that in all of the hundreds of 
> thousands of pages that make up the Perl documentation 
> (official and unofficial) every one of the questions posted
> here could be adequetly answered using the "docs".

Many of them, even most, but not all. Sometimes the docs aren't quite
complete. On rare occasions, Perl doesn't behave as documented. Many
posters seek help in finding bugs, or in finding a better algorithm, or
just comments on their code.

> However, I believe that a good portion of users of this newsgroup
> find it easier and more productive to shoot out a quick question 
> here than pour over hundreds of pages looking for that specific
> answer.

And that's the problem. Too many people asking the same questions over
and over. That's *why* there's an FAQ. That's *why* it's included with
the documentation. And there's no reason to have to go wade through
everything to find your answers; perldoc is searchable.

perldoc -f <function> # Show manpage for <function>
perldoc -q <keyword>  # Find FAQs including <keyword>

Side note: tchrist is working on a new and improved utility to replace
perldoc that will make things even better and more useful.

> So stop with the docs.  Yes, it's there.  Yes, he could have
> looked.  But he didn't.  He chose to come to you for your vast
> knowledge and expertise.

Which says that he values his time more than mine. What did all these
lazy people do before Usenet?

> He trusts you more than a man page.

He shouldn't. The man pages have been reviewed by many people. I can
spout of any sort of drivel I want, including advice that if naively
followed would harm his system.

The moral of the story is, be Lazy (a programming virtue), not lazy.
When you have a question, make an effort to answer it yourself first.
That sense of self-sufficiency will give you a nice warm fuzzy. Then, if
you still can't figure it out, come here. The regulars on this group are
always delighted to assist people who sincerely want and need help, and
demonstrate that they've tried to help themselves already.

-mjc


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

Date: Fri, 1 Dec 2000 10:55:50 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Why?
Message-Id: <slrn92f0lv.cag.bernard.el-hagin@gdndev25.lido-tech>

On Thu, 30 Nov 2000 10:42:20 GMT, Ed Grosvenor <secursrver@hotmail.com>
wrote:
>I have an idea.  For those of you who insist on tearing someone a new
>orifice whenever they fail to read the Perl docs, why don't you print up a
>copy of the Perl docs and publish a phone number that these poor newbies can
>call to get a copy.

This is without a doubt the most inane thing I have _ever_ read on _any_
newsgroup. And believe me, that's saying a _lot_.

Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'


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

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


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