[17739] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5159 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 20 11:10:31 2000

Date: Wed, 20 Dec 2000 08:10:13 -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: <977328613-v9-i5159@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 20 Dec 2000     Volume: 9 Number: 5159

Today's topics:
        problem with awk in perl script <laoutaris@di.uoa.gr>
    Re: problem with awk in perl script (Rafael Garcia-Suarez)
    Re: problem with awk in perl script mike_solomon@lineone.net
    Re: problem with awk in perl script (Kenny McCormack)
    Re: problem with awk in perl script (Garry Williams)
    Re: problems with "sort" in NT (Garry Williams)
        qmail-inject <secursrver@hotmail.com>
    Re: Splitting record string into fields <russ_jones@rac.ray.com>
    Re: Splitting text, but not individual words (Eric Bohlman)
    Re: Splitting text, but not individual words (Tad McClellan)
        System Permissions <coz@paston.co.uk>
    Re: Unreserved apologies (Tad McClellan)
    Re: Where can I get CRYPT for DOS/WIN? <samuel@knm-e.se>
        Writing to Files, <coz@paston.co.uk>
    Re: Writing to Files, (Garry Williams)
    Re: Writing to Files, mike_solomon@lineone.net
    Re: Writing to Files, (Abigail)
    Re: Writing to Files, (Anno Siegel)
    Re: yet another question: is ' more efficient than "? (Abigail)
    Re: yet another question: is ' more efficient than "? (Abigail)
    Re: yet another question: is ' more efficient than "? (Randal L. Schwartz)
    Re: yet another question: is ' more efficient than "? <bart.lateur@skynet.be>
    Re: yet another question: is ' more efficient than "? <timallen449@coldmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 20 Dec 2000 15:07:14 +0200
From: "Nikos Laoutaris" <laoutaris@di.uoa.gr>
Subject: problem with awk in perl script
Message-Id: <91qbbv$g9h$1@foo.grnet.gr>

Hello evrybody in the numerous newsgroups that i am posting

I have a problem with a rather simple awk command that i am issuing from
inside a perl script using the system() call.

The awk command is

awk '{print $10,$1}' statdata.dat

which simply prints the 10th and the 1st token from each line of
statdata.dat (tubullar format). When i run the command from the command
prompt of solaris it returns as expected.

I try to call awk from perl with

system(`awk '{print $10,$1}' statdata.dat `);

which should do the same. This time awk complains:

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1

I have tried escaping \' because i assumed that the ' of awk confuses perl
but the problem remains. I also tried to escape $ in the awk command but
again i got the same problem. Can someone please help. I am not a unix guru
just an ordinary user. What am i missing here?

Thanx

--
Nikos Laoutaris
Communication Networks Laboratory
National and Kapodestrian University of Athens, Greece
e-mail : laoutaris@noc.uoa.gr
tel. : +301 7275603
fax : +301 7275601




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

Date: Wed, 20 Dec 2000 13:30:56 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: problem with awk in perl script
Message-Id: <slrn941d3s.p8a.rgarciasuarez@rafael.kazibao.net>

Nikos Laoutaris wrote in comp.lang.perl.misc:
> 
> I have a problem with a rather simple awk command that i am issuing from
> inside a perl script using the system() call.
> 
> The awk command is
> 
> awk '{print $10,$1}' statdata.dat
>
> which simply prints the 10th and the 1st token from each line of
> statdata.dat (tubullar format). When i run the command from the command
> prompt of solaris it returns as expected.
> 
> I try to call awk from perl with
> 
> system(`awk '{print $10,$1}' statdata.dat `);

The backquotes return the output of the awk command. Your Perl line
tries to execute this output as a shell command via the system()
function. Bad idea : remove the system().

Moreover, Perl interpolates the variables into backquotes. That's why
awk complains. You wanted to do :
  `awk '{print \$10,\$1}' statdata.dat`

But this reads the whole output of the awk command into memory before
executing the rest of the program. It's better to use a pipe :

  open AWK, q(awk '{print $10,$1}' statdata.dat |)
    or die "Can't open pipe: $!\n";
  while (<AWK>) { ... }
  close AWK or die "Can't close pipe: $!\n";

But even this solution is not good enough. Perl is a very powerful text
processing tool. Much more powerful than awk. It's awk-ward to call awk
from inside a Perl program. Take some time to learn the basics of Perl
and to reimplement this using only Perl commands! You'll end with a
faster, more portable and more maintenable program.

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


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

Date: Wed, 20 Dec 2000 13:50:15 GMT
From: mike_solomon@lineone.net
Subject: Re: problem with awk in perl script
Message-Id: <91qdel$umg$1@nnrp1.deja.com>

In article <91qbbv$g9h$1@foo.grnet.gr>,
  "Nikos Laoutaris" <laoutaris@di.uoa.gr> wrote:
> Hello evrybody in the numerous newsgroups that i am posting
>
> I have a problem with a rather simple awk command that i am issuing
from
> inside a perl script using the system() call.
>
> The awk command is
>
> awk '{print $10,$1}' statdata.dat
>
> which simply prints the 10th and the 1st token from each line of
> statdata.dat (tubullar format). When i run the command from the
command
> prompt of solaris it returns as expected.
>
> I try to call awk from perl with
>
> system(`awk '{print $10,$1}' statdata.dat `);
>
> which should do the same. This time awk complains:
>
> awk: syntax error near line 1
> awk: illegal statement near line 1
> awk: syntax error near line 1
> awk: illegal statement near line 1
> awk: syntax error near line 1
> awk: illegal statement near line 1
>
> I have tried escaping \' because i assumed that the ' of awk confuses
perl
> but the problem remains. I also tried to escape $ in the awk command
but
> again i got the same problem. Can someone please help. I am not a
unix guru
> just an ordinary user. What am i missing here?
>
> Thanx
>
> --
> Nikos Laoutaris
> Communication Networks Laboratory
> National and Kapodestrian University of Athens, Greece
> e-mail : laoutaris@noc.uoa.gr
> tel. : +301 7275603
> fax : +301 7275601
>
Why are you using awk within a Perl script?

you can use Perl to do eveything awk does

to convert awk scripts to Perl you can use a utility called a2p


Regards

Mike Solomon


Sent via Deja.com
http://www.deja.com/


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

Date: 20 Dec 2000 08:48:59 -0600
From: gazelle@yin.interaccess.com (Kenny McCormack)
Subject: Re: problem with awk in perl script
Message-Id: <91qgsr$fm5$1@yin.interaccess.com>

In article <91qdel$umg$1@nnrp1.deja.com>,  <mike_solomon@lineone.net> wrote:
 ...
>Why are you using awk within a Perl script?  You can use Perl to do
>eveything awk does to convert awk scripts to Perl you can use a utility
>called a2p

The most likely answer to this is that the OP is using Perl more or less as
a shell, rather than as a programming language.  Given what a crappy
language Perl is qua language, this is understandable.  Probably some
company mandate that it be used in place of the the more conventional
shells.

The most likely answer to the original question is a PATHing problem.  The
error messages look like those generated by "old AWK" - making it look like
there is some alias or PATH setup in the shell that causes "awk" to invoke
"nawk" or "gawk" (or some other modern AWK), but that inside Perl, he's
picking up /bin/awk (on Solaris).


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

Date: Wed, 20 Dec 2000 15:18:53 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: problem with awk in perl script
Message-Id: <x5406.499$Kk5.25445@eagle.america.net>

On 20 Dec 2000 08:48:59 -0600, Kenny McCormack
<gazelle@yin.interaccess.com> wrote:
>The most likely answer to the original question is a PATHing problem.
>The error messages look like those generated by "old AWK" - making it
>look like there is some alias or PATH setup in the shell that causes
>"awk" to invoke "nawk" or "gawk" (or some other modern AWK), but that
>inside Perl, he's picking up /bin/awk (on Solaris).

Nope.  

Others have pointed out that the shell is interpolating his perl
variables before awk gets the code and that the quote marks are gone
by the time the shell got the string.  There is nothing special about
his awk program that requires gawk or others.  There is nothing in the
error messages he posted that would lead one to believe that either.  

    $ uname -a
    SunOS zweb 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-60
    $ awk {print $10, $1} < /dev/null
    awk: syntax error near line 1
    awk: illegal statement near line 1
    $ awk '{print $10, $1}' < /dev/null
    $ 

-- 
Garry Williams


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

Date: Wed, 20 Dec 2000 13:33:36 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: problems with "sort" in NT
Message-Id: <Qy206.486$Kk5.24832@eagle.america.net>

On Tue, 19 Dec 2000 21:39:14 -0500, Randy Harris <harrisr@bignet.net>
wrote:
><estelnet@my-deja.com> wrote in message
>news:91okiq$jbu$1@nnrp1.deja.com...
>> I need to translate this code line for run in NT.
>>
>> system "sort", "$dircgi/archive.dat", "-n", "-o",
>> "$dircgi/archive2.dat";
>
>This isn't really a Perl question.  DOS sort isn't very smart.  I think
>that "-n" means to do a numeric sort, DOS doesn't.  You might try
>something like:
>
>system "sort", "< $dircgi/archive.dat", "> $dircgi/archive2.dat";

You might try it, but it won't have the effect you intended.  

If you want the shell to do redirection, let the shell run the
command.  See the section on system() or exec() in the perlfunc manual
page.  

The original poster's problem is probably not solvable without
reformatting the file and making the numeric first field a fixed
length field.  

-- 
Garry Williams


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

Date: Wed, 20 Dec 2000 15:09:49 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: qmail-inject
Message-Id: <1Z306.843$ep6.94376@newsread2.prod.itd.earthlink.net>

Hey guys.  My hosting provider uses qmail-inject instead of sendmail.  The
only information I can really get on this thing is that it works like
sendmail in that you pipe your input to it.  It's not all that hard to use,
but every once in a great while, I get an error that reads "Use of
uninitialized value at line 100..."  Well, that's great, except that the man
pages (which are all I can get my hands on it seems) don't exactly tell you
what's at line 100.  I follow the instructions and the error seems almost
arbitrary.

So what I was wondering is if any of you knows where I might be able to get
my hands on an actual real copy of qmail-inject.  I don't know if it's open
source.  At this point, I'd be willing to pay for licensing if it's not too
outrageous.  I don't even know who writes the stuff, but my searches for the
source have proven fruitless.  I would really appreciate any help on this
one.

Ed




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

Date: Wed, 20 Dec 2000 08:00:10 -0600
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Splitting record string into fields
Message-Id: <3A40BB6A.AAB69685@rac.ray.com>



Bart Lateur wrote:
> 
> appsman1368@my-deja.com wrote:
> 
> >I really don't have the time to learn perl at the
> >moment
> 
> Then this newsgroup is not for you.
> 
> I'm pretty sure MS Access, and even MS Excel, are perfectly capable of
> importing wixed width records, in a wizard-like fashion.
> 

Be vewwy quiet, we're wixxing wecords.

-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: 20 Dec 2000 11:15:25 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Splitting text, but not individual words
Message-Id: <91q4cd$kmb$4@bob.news.rcn.net>

Jerome Abela <Jerome.Abela@free.fr> wrote:
> If you are not willing to use Text::Wrap, here is a single-line,
> pattern-only
> solution:

>     s/(.{0,80})( |)/\1\n/g;

Someone who, for whatever reason, is unwilling to use Text::Wrap should
also consider using Perl formats to do the job; Tom C will probably be
around with a suggestion.



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

Date: Wed, 20 Dec 2000 07:52:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Splitting text, but not individual words
Message-Id: <slrn941ark.24o.tadmc@magna.metronet.com>

Jerome Abela <Jerome.Abela@free.fr> wrote:

>If you are not willing to use Text::Wrap, here is a single-line,
>pattern-only
>solution:
 ^^^^^^^^
>    s/(.{0,80})( |)/\1\n/g;


For some loose definition of "solution" I suppose.

Code that generates warnings is always suspect as well.

If the 81st character is not a space, then the line is
not broken at all, there are just some extra newlines
at the end.


----------------------------------
#!/usr/bin/perl -w
use strict;
use Text::Wrap;

$_ = '0123456789' x 7;
$_ .= ' 0123456789' x 2;
$_ .= "\n";

print "----------\n";
print '0123456789' x 8, "\n";  # ruler line
print wrap( '', '', $_);

print "----------\n";
s/(.{0,80})( |)/$1\n/g;
print '0123456789' x 8, "\n";  # ruler line
print;
print "----------\n";
----------------------------------


output:

----------
01234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789
0123456789 0123456789
----------
01234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789 012345678
9 0123456789



----------


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


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

Date: Wed, 20 Dec 2000 15:11:24 -0000
From: "Marcus" <coz@paston.co.uk>
Subject: System Permissions
Message-Id: <91qicq$pb6$1@reader-00.news.insnet.cw.net>

I also want to write some form of CGI system administrator i.e a web form
where you enter the username, shell, group and comment and the form calls a
script that runs a useradd with these params, (Sun Solaris Server)

The trouble is that a script called by the web server has all the
permissions of a fly walking around on top of the server case !!!

Any ideas ??

Mark




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

Date: Wed, 20 Dec 2000 09:01:54 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Unreserved apologies
Message-Id: <slrn941euh.24o.tadmc@magna.metronet.com>

appsman1368@my-deja.com <appsman1368@my-deja.com> wrote:
>My sincere apologies to Tad McClellan and the group in general for my
>unforgivable outburst. 


Thank you.


>Occasionally I get dumped on by my employer
>(usually due to unexpected absence of colleagues) and put into a
>position that I have very little experience of and expected to produce
>the goods, however, it is inexcusable to vent my frustration in this
>way.


Those things happen.


But I should point out to the folks that are new to Usenet,
that, even with the apology, appsman has irrevocably damaged
his chances of getting help with all future Perl problems.

You may choose to learn from his mistakes so that you can
avoid making them yourself.

His first post earned a "soft plonk" ( -10 score ) due to the
red flag "don't have the time to learn perl". If it had been
left at that, his posts would have become visible again
in 1-3 months when I clean out my scorefile.

His followup promoted him to a "hard plonk" ( -9998 score )
due to the ad hominem. Hard plonks are one-way. Once you
earn that level, there is no going back. You're in there for good.



That won't really matter much, as there are plenty of other
people here that can help with future problems. It does
kind of leave you wondering how many "sympathetic kills"
were silently made by others with scorefiles though...


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


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

Date: Wed, 20 Dec 2000 12:18:57 +0100
From: "Samuel Rydén" <samuel@knm-e.se>
Subject: Re: Where can I get CRYPT for DOS/WIN?
Message-Id: <YI006.17$hH5.161@nntpserver.swip.net>

> Where can I get some CRYPT program for DOS/WIN worked such as CRYPT in
UNIX?

There is a crypt command in your perl software.

perldoc -f crypt

and you'll find it.

regards,


Samuel




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

Date: Wed, 20 Dec 2000 12:55:37 -0000
From: "Marcus" <coz@paston.co.uk>
Subject: Writing to Files,
Message-Id: <91qadn$n3h$1@reader-00.news.insnet.cw.net>

Thanks every one for your help about stopping new lines on scalars, I have a
better one for you now,

Is it possible to write say in the middle of a file ????

As an example if I was writing notes or messages out to a file and I wanted
to insert or delete a piece of text some where in the middle of this file,
could I do that ?? can you throw a few suggestions on this ??




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

Date: Wed, 20 Dec 2000 13:46:19 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: Writing to Files,
Message-Id: <LK206.487$Kk5.24789@eagle.america.net>

On Wed, 20 Dec 2000 12:55:37 -0000, Marcus <coz@paston.co.uk> wrote:
>Thanks every one for your help about stopping new lines on scalars, I have a
>better one for you now,
>
>Is it possible to write say in the middle of a file ????
>
>As an example if I was writing notes or messages out to a file and I wanted
>to insert or delete a piece of text some where in the middle of this file,
>could I do that ?? can you throw a few suggestions on this ??

This is a FAQ.  See "How do I change one line in a file/delete a line
in a file/insert a line..." in the perlfaq5 manual page.  

-- 
Garry Williams


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

Date: Wed, 20 Dec 2000 13:55:50 GMT
From: mike_solomon@lineone.net
Subject: Re: Writing to Files,
Message-Id: <91qdp3$v24$1@nnrp1.deja.com>

In article <91qadn$n3h$1@reader-00.news.insnet.cw.net>,
  "Marcus" <coz@paston.co.uk> wrote:
> Thanks every one for your help about stopping new lines on scalars, I
have a
> better one for you now,
>
> Is it possible to write say in the middle of a file ????
>
> As an example if I was writing notes or messages out to a file and I
wanted
> to insert or delete a piece of text some where in the middle of this
file,
> could I do that ?? can you throw a few suggestions on this ??
>
>

Yes you can

I would read the file into an array

then process the array outputing each line to a new file

when i got to the line number  after which i wanted to insert text i
would
insert the text then continue processing the array

I hope this helps and is what you meant


Regards

Mike Solomon



Sent via Deja.com
http://www.deja.com/


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

Date: 20 Dec 2000 14:39:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Writing to Files,
Message-Id: <slrn941h44.vhs.abigail@tsathoggua.rlyeh.net>

Marcus (coz@paston.co.uk) wrote on MMDCLXVIII September MCMXCIII in
<URL:news:91qadn$n3h$1@reader-00.news.insnet.cw.net>:
:) Thanks every one for your help about stopping new lines on scalars, I have a
:) better one for you now,
:) 
:) Is it possible to write say in the middle of a file ????
:)
:) As an example if I was writing notes or messages out to a file and I wanted
:) to insert or delete a piece of text some where in the middle of this file,
:) could I do that ?? can you throw a few suggestions on this ??


You're not the first to ask. In fact, it's frequently asked.
Hence, see the FAQ.



Abigail
-- 
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()


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

Date: 20 Dec 2000 14:58:42 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Writing to Files,
Message-Id: <91qhf2$mnh$1@lublin.zrz.tu-berlin.de>

 <mike_solomon@lineone.net> wrote in comp.lang.perl.misc:
>In article <91qadn$n3h$1@reader-00.news.insnet.cw.net>,
>  "Marcus" <coz@paston.co.uk> wrote:

>> Is it possible to write say in the middle of a file ????
>>
>> As an example if I was writing notes or messages out to a file and I
>wanted
>> to insert or delete a piece of text some where in the middle of this
>file,
>> could I do that ?? can you throw a few suggestions on this ??
>
>Yes you can
>
>I would read the file into an array

Why?  Nothing in the problem makes it necessary, or even desirable,
to load all of the file into memory at once.  So why do it? 

>then process the array outputing each line to a new file
>
>when i got to the line number  after which i wanted to insert text i
>would
>insert the text then continue processing the array

You can do that just as well when you are reading the original file
line by line.  Slurping the file only makes you program less scalable.
It doesn't have a single advantage.

The propensity of aspiring Perl programmers to read complete files
for no good reason is disturbing.  I wonder how this deplorable
tradition got started.

Anno


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

Date: 20 Dec 2000 11:55:18 GMT
From: abigail@foad.org (Abigail)
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <slrn9417h6.vhs.abigail@tsathoggua.rlyeh.net>

AP (alex@hoopsie2.com) wrote on MMDCLXVIII September MCMXCIII in
<URL:news:3A403B49.A748999E@hoopsie2.com>:
"" Is using single quotes more efficent than using double?
"" 
"" print 'my name is joe';
"" 
"" vs.
"" 
"" print "my name is joe";
"" 
"" 
"" Notice that nothing is being interpolated.  I would guess that it has to be
"" more efficient since perl doesn't have to look for anything to interpolate. 
"" The only thing it would look for are escaped single quotes and/or forward
"" slashes.  Am I wasting my time single quoting things?


Yes. If there's any difference, it's at compile time. Any difference is
so minute, you've probably used more time writing the above posting then
you would gain in your lifetime with the difference between single and
double quotes.



Abigail
-- 
perl -wle'print"Êõóô áîïôèåò Ðåòì Èáãëåò"^"\x80"x24'


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

Date: 20 Dec 2000 12:05:49 GMT
From: abigail@foad.org (Abigail)
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <slrn94184t.vhs.abigail@tsathoggua.rlyeh.net>

Eric Bohlman (ebohlman@omsdev.com) wrote on MMDCLXVIII September MCMXCIII
in <URL:news:91q30f$kmb$2@bob.news.rcn.net>:
][ 
][ While you're certainly correct that there's no speed or space efficiency
][ gained by using single quotes where no interpolation is needed, some,
][ including yours truly, would argue that there's a maintainability
][ gain: when you're reading through that program you wrote 6 months ago and
][ that needs to be modified yesterday, you can look at single quotes and
][ immediately say to yourself "nothing I can do short of changing this
][ literal will change the value of this string," and look at double quotes
][ and think "Ah!  This might change if I change something else."


If you have tunnel vision and see at most three of four characters at a
time, I can see your point.

The "This might change if I change something else" ought to be followed
by "... and that's probably the right thing." After all, why print a
variable if you don't want its value printed?

I don't scan code character for character; most strings are understood
as an atomic action. And I rather not waste time changing quotes when
adding a variable in a string (or removing the last one).

On top of that, other languages, (like C), use "" for strings, while
'' has a different meaning.



Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


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

Date: 20 Dec 2000 06:42:30 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <m1bsu72lyh.fsf@halfdome.holdit.com>

>>>>> "Eric" == Eric Bohlman <ebohlman@omsdev.com> writes:

Eric> While you're certainly correct that there's no speed or space efficiency
Eric> gained by using single quotes where no interpolation is needed, some,
Eric> including yours truly, would argue that there's a maintainability
Eric> gain: when you're reading through that program you wrote 6 months ago and
Eric> that needs to be modified yesterday, you can look at single quotes and
Eric> immediately say to yourself "nothing I can do short of changing this
Eric> literal will change the value of this string," and look at double quotes
Eric> and think "Ah!  This might change if I change something else."

On the flipside, I double-quote nearly everything that isn't just a
single word, because during maintenance, I'm almost always adding or
removing \n and friends, and going to back to fix a string that was
single-quoted is a pain in the hiney.

So, if you're going to write code that *I* am going to maintain,
I'd much prefer you use double-quotes on everything that doesn't
absolutely need single quotes.  Thank you.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 20 Dec 2000 15:00:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <g8i14t4stq5l6n497kmcek67m40j0am1qe@4ax.com>

AP wrote:

>Is using single quotes more efficent than using double?
>
>print 'my name is joe';
>
>vs.
>
>print "my name is joe";

Not at all. The difference between both disappears at compile time. See
the result of using O::Deparse:

test.pl:	
	#! perl -w
	print 'Hello, world!
	';

prompt>perl -MO=Deparse test.pl

-->
	print "Hello, world!\n";
	test.pl syntax OK

-- 
	Bart.


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

Date: Wed, 20 Dec 2000 16:36:23 +0100
From: "tim allen" <timallen449@coldmail.com>
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <91qj11$4ep$1@diana.bcn.ttd.net>

"AP" <alex@hoopsie2.com> wrote in message
news:3A403B49.A748999E@hoopsie2.com...
>Is using single quotes more efficent than using double?
>print 'my name is joe'; vs. print "my name is joe";

One way of answering questions like this is using Benchmark (not really my
idea-- I got this code from postings by Tad McClellan and Martien
Verbruggen)
-------- code --------
#!/usr/local/bin/perl -w
use strict;
use Benchmark;

my @a = qw(foo bar baz banana);
print "\$#a = $#a\n";

timethese(-2, {
    concat => sub { my $str = ""; $str .= $_ for @a },
    join   => sub { my $str = ""; $str = join '', @a },
    empty  => sub { my $str = "" }
});

@a = (@a) x 100;
print "\$#a = $#a\n";

timethese(-2, {
    concat => sub { my $str = ""; $str .= $_ for @a },
    join   => sub { my $str = ""; $str = join '', @a },
    empty  => sub { my $str = "" }
});
------- output -------------
Sample: hello, world
Benchmark: running double, single, each for at least 2 CPU seconds...
    double:  3 wallclock secs ( 2.20 usr +  0.00 sys =  2.20 CPU) @
180949.55/s (n=398089)
    single:  1 wallclock secs ( 2.14 usr +  0.00 sys =  2.14 CPU) @
226195.79/s (n=484059)
           Rate double single
double 180950/s     --   -20%
single 226196/s    25%     --

A slightly longer string, which should be bigger and stuff
Benchmark: running double, single, each for at least 2 CPU seconds...
    double:  3 wallclock secs ( 2.10 usr +  0.00 sys =  2.10 CPU) @
71086.19/s (n=149281)
    single:  3 wallclock secs ( 2.08 usr +  0.00 sys =  2.08 CPU) @
71769.71/s (n=149281)
          Rate double single
double 71086/s     --    -1%
single 71770/s     1%     --

A really long string
Benchmark: running double, single, each for at least 2 CPU seconds...
    double:  2 wallclock secs ( 2.08 usr +  0.00 sys =  2.08 CPU) @
4622.12/s (n=9614)
    single:  3 wallclock secs ( 2.75 usr +  0.00 sys =  2.75 CPU) @
4449.82/s (n=12237)
         Rate single double
single 4450/s     --    -4%
double 4622/s     4%     --

---------end of output ----------
As I interpret this, double quotes were 20% less efficient for a short
string, and 1% less efficient for a slightly longer string, and 4% less
efficient for a long string of 1061 bytes.  None of these strings contained
variables to interpret.  Check p.875 of Programming Perl

 -tim
--
unmunge?cold=hot






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

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


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