[8101] in Perl-Users-Digest
Perl-Users Digest, Issue: 1720 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 24 14:07:05 1998
Date: Sat, 24 Jan 98 11:00:31 -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 Sat, 24 Jan 1998 Volume: 8 Number: 1720
Today's topics:
can not run a brand new install of PERL <*aalejan@pacbell.net>
Re: Can't get Perl to find modules in Lib directory whe (Gabor)
Copying files for WIN32 <ordway@iwshost.net>
File::Find feature? How to preserve stat buffer? <alexis@danae.demon.co.uk>
Re: Finding the missing bracket? <doug@tc.net>
Re: Finding the missing bracket? <rjk@coos.dartmouth.edu>
Re: Help Renaming Files.... (Clay Irving)
Re: Help w/ regexp <rjk@coos.dartmouth.edu>
Re: Help with an Array of instances (Dave Frascone)
Re: Help with an Array of instances (Mark-Jason Dominus)
Re: How to get at stuff piped into Perl? (Tad McClellan)
Re: HTML perl scripts for Windows NT <Scott_A_Willsey@ccm.fm.intel.com>
Re: HTML perl scripts for Windows NT (Jim Michael)
IP Address as new File <drew@citypost.com>
Re: MacPerl CD-ROM, Version 0.5 (Tony L. Svanstrom)
Re: MacPerl CD-ROM, Version 0.5 (Chris Nandor)
Re: Oraperl and long type <schramm@one.net>
Req: CGI PERL with HTML TABLE HELP (Nucci Stefano)
Re: Req: CGI PERL with HTML TABLE HELP (brian d foy)
small question about substitution. <seong@cse.bridgeport.edu>
Re: Some help with the 'reverse' command please..... (Mark-Jason Dominus)
Re: Sort help please <rjk@coos.dartmouth.edu>
Re: Survival Of perl <ebohlman@netcom.com>
Re: Survival Of perl (Clay Irving)
typeglob? <gcyriac@internetmci.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 24 Jan 1998 09:58:01 -0800
From: "Aldo Alejandro" <*aalejan@pacbell.net>
Subject: can not run a brand new install of PERL
Message-Id: <6ada7q$iau$1@nnrp2.snfc21.pbi.net>
Please tell me what I am doing wrong as I can not run the downloaded 5.003
"Build "315" version of win32 from activestate.
a) I unzipped it
b) Installed to g:\perl directory
c) automatically installed the perlw32 install file
d) rebooted
e) I tried both methods
1) double clicking the executable file in windows
2) running the command through the dos line
f) typed
#!/usr/bin/perl -w
print ("Hello, world!\n");
Nothing happens after pressing the return key.
--
Thanks & have a nice day! ;-)
Remove the "*" when replying
------------------------------
Date: 24 Jan 1998 15:08:15 GMT
From: gabor@vnode.vmunix.com (Gabor)
Subject: Re: Can't get Perl to find modules in Lib directory when compiling
Message-Id: <slrn6ck0jh.hpc.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, John Petri <jpetri@iw.net> wrote :
# Could someone please help,
# I'm having a problem when my scripts compile.
# Perl doesn't seem to know where to look when it loads modules (they're in
# the Lib directory.)
# Is there some configuration I need to do first?
#
# Thanks,
# John.
#
What do you mean by 'Lib directory'?
Try this and see if your directory is in @INC;
perl -e '$" = "\n";print "@INC\n";'
if it isn't then try this
BEGIN {
push @INC,"full path to your lib dir";
}
use module version;
gabor.
--
If you want your program to be readable, consider supplying the argument.
-- Larry Wall in the perl man page
------------------------------
Date: Sat, 24 Jan 1998 07:07:07 -0600
From: "Brandon" <ordway@iwshost.net>
Subject: Copying files for WIN32
Message-Id: <6acot7$76m$1@reggie.win.bright.net>
Lets say that I have a file- c:/myfile.txt
With perl for win32, how can I copy it to this dir- c:/mydir/ ??
Email me at ordway@iwshost.net or reply this post.
Thanks!!
------------------------------
Date: 24 Jan 1998 15:15:47 GMT
From: Alexis Huxley <alexis@danae.demon.co.uk>
Subject: File::Find feature? How to preserve stat buffer?
Message-Id: <enanqb.2f8@danae.demon.co.uk>
Hi
finddir() in Find.pm contains:
1 &$wanted;
2 if ($subcount > 0 || $dont_use_nlink) { # Seen all the subdirs?
3 ($dev,$ino,$mode,$nlink) = ($Is_VMS ? stat($_) : lstat($_));
4 if (-d _) {
5 # run finddir() on that subdirectory
Now since
I'm not on a VMS system (and so line 3 can call lstat() instead
of stat())
and
the manual *does* say that the '_' file handle refers to the
last stat()ed file without mentioning the last lstat()ed file
and
my wanted() function can call stat() and lstat() on items other
than the name passed to it - including calls on non-directories
it can happen that
the file tested by the '(-d _)' on line 4 may not be that operated
upon in line 3!
Since that manual doesn't mention that File::Find is immune to such
situations I cannot consider this a bug. But in order to work around this
my question is:
How can my wanted() function save a copy of the stat() and lstat()
structures and then restore them prior to its own exit? i.e.
sub wanted
{
# save lstat() and stat() buffers
# do my own stuff
# restore lstat() and stat() buffers
}
Obviously I can stat($name) just before returning, but that assumes that
finddir in File::Find will *always* stat($name) and not some other file or
directory. So it necessitates that I have a knowledge of how it works
internally - which I'd rather not have to know (and track). So ... does
anybody have any ideas?
Is this a bug? If not then how do I call stat() in my wanted() function in
a way that won't upset File::Find when finddir() continues? Any suggestions
would be appreciated. I'll summarise if anyone's interested.
Thanks.
Alexis
--
Alexis Huxley Delfyn on IRC (EFNet)
alexis@danae.demon.co.uk Email key: 549812
http://www.danae.demon.co.uk/ PGP key, CV, Unix S/W, info, Rilke
"I think you think I can't think" Program in 1991 BCM Turing Test
------------------------------
Date: 24 Jan 1998 10:56:48 -0500
From: Douglas McNaught <doug@tc.net>
Subject: Re: Finding the missing bracket?
Message-Id: <m2vhv9lvb3.fsf@ono.tc.net>
mbudash@sonic.net (Michael Budash) writes:
> Could you (and/or the others 'round here) be so kind as to recommend such
> an editor, i.e., one that is perl-savvy?
GNU Emacs or XEmacs with cperl-mode.el. Does a hard job really well.
GNU Emacs runs on Win32 if you're a PoB.
-Doug
--
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";
------------------------------
Date: Sat, 24 Jan 1998 12:12:49 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Finding the missing bracket?
Message-Id: <34CA2111.A178761B@coos.dartmouth.edu>
Michael Budash wrote:
>
> In article <Pine.GSO.3.96.980123134723.17597Q-100000@user2.teleport.com>,
> Tom Phoenix <rootbeer@teleport.com> wrote:
>
> >> A programmers' text editor should be able to help you indent code properly
> >> and to match up braces in pairs.
>
> Could you (and/or the others 'round here) be so kind as to recommend such
> an editor, i.e., one that is perl-savvy?
emacs
Did you have a specific platform in mind?
Chipmunk
------------------------------
Date: 24 Jan 1998 12:31:12 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Help Renaming Files....
Message-Id: <6ad8h0$hgb@panix.com>
In <34C96D07.2A14@polaccess.com> Marcin Pasek <marcin@polaccess.com> writes:
>I have a bunch of HTM files and I want to rename them so that they are
>in some kind of order....someone wrote a short program that he said
>will work but it's not...Well this program has to take each file name
>put XDR and then consecutive number right after so that I get names
>like
>xdr1.htm, xdr2.htm, xdr3.htm and so far....Here is a code can someone
>help figure this one out...Thanks
>#!/usr/bin/perl
>opendir(DIR,".");
Did it succeed? Maybe you want to test the opendir...
>$count = 1;
>while ($thisfile=readdir(DIR))
>{
Instead of this:
>$_ = $thisfile;
>if (/\.htm/)
You could write:
if ($thisfile =~ /\.htm$/)
/\.htm/ will match foo.htm.bar.
>{
>$newfile = "xdr" . $count . ".htm";
You never increment $count -- For every file matching the pattern, you'll
rename it xdr1.htm -- I don't think that's what you intend to do.
>system ("mv $thisfile $newfile");
Now you've destroyed all but one file matching the pattern. You should
also test the mv command succeeded (if you insist on making a system call).
>print "I moved $thisfile $newfile\n";
>}
>}
>exit(0);
--
Clay Irving <clay@panix.com> I think, therefore I am. I think?
http://www.panix.com/~clay/
------------------------------
Date: Sat, 24 Jan 1998 12:22:21 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Douglas Clifton <doug1@weboneinc.com>
Subject: Re: Help w/ regexp
Message-Id: <34CA234D.675BE7C6@coos.dartmouth.edu>
[posted and mailed]
Douglas Clifton wrote:
>
> To be more to-the-point: given an array that has N
> tab delimited fields ending in a number (day into the
> year) I want to remove all lines not in the above
> mentioned range. Rather than using a loop and split()
> I thought it might be simplier to use grep():
>
> @log = grep /[$beg-$end]\n$/, @log;
You can use the suggestions you've already received in the grep:
@log = grep {/(\d+)$/ and $1 >= $beg and $1 <= $end} @log
Chipmunk
------------------------------
Date: Sat, 24 Jan 1998 14:42:39 GMT
From: chaos@mindspring.com (Dave Frascone)
Subject: Re: Help with an Array of instances
Message-Id: <34c9fd87.265752405@news.mindspring.com>
On Fri, 23 Jan 1998 16:42:30 -0500, comdog@computerdog.com (brian d
foy) wrote:
Here is some *exact* code that fails. Every instance has the same
$self{_arg} value.
------------------------------ cut here ------------------------------
package Test;
sub new {
my $type=shift;
my $self={};
my @args=@_;
$self{_arg}=shift @args;
bless $self,$type;
}
sub arg{
my $self=shift;
return $self{_arg};
}
package main;
@MyArray=();
for $i (0..10) {
# my $temp=Test->new($i);
# push @MyArray, $temp;
push @MyArray, Test->new($i);
}
foreach $i (@MyArray) {
my $value=$i->arg();
print "Value: $value\n";
}
-------------------------------------cut here------------------------
When I run it I get Value=10, Value=10, etc
Thanks in advance,
Dave
P.S. Perl v5.004,
>In article <34c81bc5.142403637@news.mindspring.com>, chaos@mindspring.com (Dave Frascone) posted:
>
>>I am trying to make an array of instances. For some reason, I can't
>>quite get it to work. This is not my exact code, but this is what I
>>am trying:
>
>sometimes it's a bit of the exact code that is wrong - and it's
>something not reproduced in an example snippet...
>
>
>>package Something;
>>
>>@Instances=();
>>sub initialize {
>> my $instance;
>> my $i;
>>
>> for $i (0 .. 10) {
>> $instance = Something->new($i);
>> push @Instances, $instance;
>> }
>>}
>>
>>When I get out of the loop, and look at @Instances, all of them are
>>the same! (They contain the same data.) I've tried storing
>>references (push @Instances, \$instance)
>
>based on that snippet i can't see anything wrong. there's nothing
>special about storing objects in a list, either. perhaps
>the constructor is not doing what you expect? perhaps you'd
>like to localize $instance to within the for loop?
>
>--
>brian d foy <comdog@computerdog.com>
>CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
>Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
------------------------------
Date: 24 Jan 1998 13:27:58 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Help with an Array of instances
Message-Id: <6adbre$1f8$1@monet.op.net>
Keywords: Keynesian lit must reputation
In article <34c9fd87.265752405@news.mindspring.com>,
Dave Frascone <chaos@mindspring.com> wrote:
> my $self={};
This makes the scalar variable $self contain a reference to an anonymous hash.
> $self{_arg}=shift @args;
This sets elements in the hash variable %self, which is completely
unrelated to $self that you set up above.
You should have written
$self->{_arg}
Which means to look in $self, find the hash that it is a reference to,
and get the _arg item from that hash.
Similarly, here:
>sub arg{
> my $self=shift;
> return $self{_arg};
>}
you should have had $self->{_arg};
------------------------------
Date: Sat, 24 Jan 1998 06:31:37 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to get at stuff piped into Perl?
Message-Id: <9vmca6.ji.ln@localhost>
Michael Kairys (kairys@mi.sl.com) wrote:
: Environment: Windows NT, Perl 5.04.04
: I want to pipe lists of files into Perl and assemble them into a command,
: eg.
: > grep foo * | myscript.pl
: I can't figure out how to get at the output of the grep once I'm in
: myscript.pl.
while (<>) {
print "grep found: $_";
}
: I've read all the references I can find about pipes but they
: all seem to be talking about using open and creating a process to read/write
: from/to.
That sounds like pipes within perl.
In your example above, it is the _shell_ doing the piping.
Your perl script just reads from STDIN.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 24 Jan 1998 03:26:00 -0800
From: Scott Willsey <Scott_A_Willsey@ccm.fm.intel.com>
Subject: Re: HTML perl scripts for Windows NT
Message-Id: <34C9CFC8.814B48C0@ccm.fm.intel.com>
jlk wrote:
> How about Windows NT?
> I don't think I can use #!/usr/local/bin/perl as perl path.
> Thank you....
You're right. But you can use #!c:\perl or wherever you installed perl
win32 to.
Scott
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I don't speak for Intel, and
they wouldn't want to say
what I'm thinking either!
------------------------------
Date: Sat, 24 Jan 1998 16:30:54 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: HTML perl scripts for Windows NT
Message-Id: <genepoolEnAr7I.AJD@netcom.com>
Scott Willsey (Scott_A_Willsey@ccm.fm.intel.com) wrote:
: jlk wrote:
: > How about Windows NT?
: > I don't think I can use #!/usr/local/bin/perl as perl path.
: You're right. But you can use #!c:\perl or wherever you installed perl
: win32 to.
The shebang line is ignored other than switches such as -w, so you can
leave the !#/usr/bin/perl there for compatibility on *nix boxes.
Cheers,
Jim
------------------------------
Date: 24 Jan 1998 17:54:51 GMT
From: "InterActive Promotions" <drew@citypost.com>
Subject: IP Address as new File
Message-Id: <01bd28f0$8e66b640$f8a7f3ce@tom>
can someone help ?
I am trying to create a new file based on a users IP Addrss.
I have tryed:
$remote_address = $ENV{'REMOTE_ADDR'};
open (TEMP_FILE, "$remote_address");
print TEMP_FILE ("$remote_address|$url\n");
close (TEMP_FILE);
This is just part of the script.
Thanks in advance
Andrew
drew@citypost.com
------------------------------
Date: Sat, 24 Jan 1998 13:23:25 +0100
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: MacPerl CD-ROM, Version 0.5
Message-Id: <1d3d3n4.1p1grp615sdli8N@du31-253.ppp.algonet.se>
Rich Morin <rdm@cfcl.com> wrote:
> Prime Time Freeware (PTF; http://www.ptf.com) is pleased to announce the
> MacPerl CD-ROM (Version 0.5). This disc,
Is this a good buy for someone that wants to learn Perl when the scripts
will be used on UN*Xmachines only?
/Tony
--
/\___/\
\_@ @_/
---------------------oOO-(_)-OOo----------------------
"We only live to please those we love" -- Aphrael
----------------------ttt---ttt-----------------------
http://tls.base.org \O/ \O/ )Tony Svanstrom 1997
------------------------------
Date: Sat, 24 Jan 1998 10:38:30 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: MacPerl CD-ROM, Version 0.5
Message-Id: <pudge-2401981038300001@ppp-3.ts-1.kin.idt.net>
In article <1d3d3n4.1p1grp615sdli8N@du31-253.ppp.algonet.se>,
tony@svanstrom.com (Tony L. Svanstrom) wrote:
# Rich Morin <rdm@cfcl.com> wrote:
#
# > Prime Time Freeware (PTF; http://www.ptf.com) is pleased to announce the
# > MacPerl CD-ROM (Version 0.5). This disc,
#
# Is this a good buy for someone that wants to learn Perl when the scripts
# will be used on UN*Xmachines only?
If you will only be using Unix, no. It is an HFS (Mac-format) disk. If
you will be using MacPerl to write scripts for use on Unix, then yes, it
is good for that.
--
Chris Nandor pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== MacPerl: Power and Ease ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Sat, 24 Jan 1998 13:02:03 -0500
From: "R. Schramm" <schramm@one.net>
Subject: Re: Oraperl and long type
Message-Id: <34ca2ca4.0@news.one.net>
Try this: After your use or require statement on the module, set
$ora_long=12000. Then, log into the database.
See DBD Oracle for more information on this. It sets the max length that at
long field can return, maybe it will fix update problem as well.
Christian Mondrup wrote in message <6a73gk$9b4$1@news.net.uni-c.dk>...
>M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>: Christian Mondrup <scancm@biobase.dk> wrote:
>: >: Monica Fernandez Barreiro <monica@enol.tid.es> wrote:
>: >: : Hello:
>: >: : I have a problem when I try to insert a variable long type
>: >: : in the data base. In a exactly way I'm going to write the
>: >: : code and the place where it doesn't work:
>: >
>: >: : $txt = "insert into cuerpo_certificados
>: >: : (email_mayusculas, codigo) values
>: >: : ('$email_upper', :1)";
>: >
>: >Sorry for the error. What I meant was
>: >
>: > $txt = "insert into cuerpo_certificados
>: > (email_mayusculas, codigo) values
>: > (\'$email_upper\', :1)";
>
>: What difference is that supposed to make? ' isn't a special character
>: inside "". If you want to get a \ into the final string, you'll need
>: to write \\' not \'.
>
>Thank you for pointing that out. Until now I _did_ think it was necessary
to
>escape singe quotes in order to pass them to Oracle - it isn't !
>
>: But I suspect the original error is somewhere entirely different.
>
>
>: Mike Guy
>
>--
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>+ Christian Mondrup, Computer Programmer +
>+ Scandiatransplant, Skejby Hospital, University Hospital of Aarhus +
>+ Brendstrupgaardsvej, DK 8200 Aarhus N, Denmark +
>+ Phone: +45 89 49 53 01, Telefax: +45 89 49 60 07 +
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------
Date: Sat, 24 Jan 1998 18:25:41 GMT
From: cap4648@iperbole.bologna.it (Nucci Stefano)
Subject: Req: CGI PERL with HTML TABLE HELP
Message-Id: <34ea31fe.2220945@news.comune.bologna.it>
Help me please!!!
Is there any smart way to change the background color of the cell in a
table, only for certain columns?
What I'd like to do is a CGI perl which adds the HTML tags for
changing the color of the cells in the first and third coloums in a
table.
How can I do it?
Please, send your mail to:
cap4648@iperbole.bologna.it
------------------------------
Date: Sat, 24 Jan 1998 13:57:32 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Req: CGI PERL with HTML TABLE HELP
Message-Id: <comdog-2401981357320001@news.panix.com>
Keywords: just another new york perl hacker
In article <34ea31fe.2220945@news.comune.bologna.it>, cap4648@iperbole.bologna.it posted:
> Is there any smart way to change the background color of the cell in a
> table, only for certain columns?
probably, but that would be an HTML thing, not a Perl or CGI thing.
you might want to see the appropriate documentation for table
extensions.
--
brian d foy <http://computerdog.com>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
------------------------------
Date: Fri, 23 Jan 1998 13:08:10 -0500
From: "Seong Y. Kim" <seong@cse.bridgeport.edu>
Subject: small question about substitution.
Message-Id: <34C8DC8A.127D@cse.bridgeport.edu>
Hi, can anyone help me?
$tmp = "/opt/guide/acumedia/HTML/cgibin";
$tmp = ~ s/^\/opt\/guide\/acumedia/http:\/\/www\.seong\.com/;
print $tmp;
what I am trying to do is substituting string
"/opt/guide/acumedia/HTML/" with "http://www.seong.com"
when i run it, it gives me -1
can anyone tell me why and How i can substitute. . . .
thanks
------------------------------
Date: 24 Jan 1998 12:47:20 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Some help with the 'reverse' command please.....
Message-Id: <6ad9f8$17r$1@monet.op.net>
Keywords: glycerol payroll perceptual recitative
In article <34C97BC7.610B19B7@inav.net>, Steel Viper <sviper@inav.net> wrote:
>@string_array = <STDIN>;
>
>@string_array = reverse(@string_array);
>print("\n@string_array\n");
>print("\n" . reverse(@string_array) . "\n");
>
>
>If this is run, the first print statement prints out the lines in the
>opposite order they were entered, however the second print statement
>reverses the entire line one at a time. I do not understand what is
>going on.
That is a very good question, and it goes right to the heart of a very
important and unusual feature of the Perl language, so it'll take a
little while to explain. Please bear with me through this explanation
of one of Perl's central concepts.
Every Perl expression is in one of two `contexts', either `list
context' or `scalar context', depending on whether it is expected to
produce a list or a scalar. Many expressions have quite different
behaviors in list context than they do in scalar context.
Here is a typical expression:
EXPRESSION
Here it is again, in a list context:
@array = EXPRESSION; # Expression is expected to produce an array
Here is how it looks in a scalar context:
$scalar = EXPRESSION; # Expression is expected to produce a scalar
The values that a particular expression has in these two contexts
might be quite different. For example, consider this simple
expression:
@q
In list context, this produces a list of the items in the array @q,
but in scalar context it prudices the _number_ of items in the array
@q.
@a = @q; # @q in list context produces a list of items from @q
$s = @q; # but in scalar context, it produces the number of items.
Similarly,
# Note two very different behaviors of // depending on context
# Put ('123.45', 'immediately') into @a
@a = /The amount was \$(\d+\.\d\d)\. You must pay ([\w\s]+)\./
# Put 1 into $s, put '123.45' into $1, put 'immediately' into $2
$s = /The amount was \$(\d+\.\d\d)\. You must pay ([\w\s]+)\./
The main point here: An expression's behavior can be drastically
different in list context than it is in scalar context.
Now we'll return to your example.
> @string_array = reverse(@string_array);
Here, `reverse' is in list context, because it's being asked to
produce a list to assign to @string_array. In list context, `reverse'
reverses the *order* of its arguments, so that the lines come out in
the *reverse order*.
Then you did
> print("\n" . reverse(@string_array) . "\n");
Now, here `reverse' is in scalar context, because it is being asked to
produce a scalar value, a string, which will be concatenated with \n
on the front and back. In a scalar context, `reverse' first
concatenates all its arguments, to get a single string, and then
reverses that string. As you know by now.
How can you get the behavior you really want? The `reverse' here
needs to be in a list context. The argument list of a function like
`print' is always a list context, so if you get rid of the
concatenation operators that are providing scalar context to
`reverse', your problem will go away:
print "\n", reverse(@string_array), "\n";
`reverse' is now expected to return a list, which will be inserted
into the list which is passed to `print'. This is probably more
efficient than what you were trying to do anyway, since `print' can
print out the many strings without bothering to concatenate them
first, as you were doing.
Again, the general rule is:
There is no general rule for deducing a function's behavior in
scalar context from its behavior in array context.
This is the cause of a lot of common errors. One mistake you didn't
make, but which we see a lot is something like this:
@a = (reverse("part"));
The programmer was expecting @a to get a list containing "trap", but
instead they got a list containing "part" again. Because `reverse'
was in a list context, it reversed the *order* of its arguments,
instead of reversing the arguments themselves, and since it only had
one argument, it ended up doing nothing.
Perl has a special operator for just such circumstances. It's called
`scalar', and it forces its argument to be evaluated in scalar
context. The last example should have been written as:
@a = (scalar(reverse("part")));
# @a now contains ("trap")
I hope this clears things up for you.
------------------------------
Date: Sat, 24 Jan 1998 13:43:43 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: andrew.spiers@virgin.net
Subject: Re: Sort help please
Message-Id: <34CA365F.3FE74AB5@coos.dartmouth.edu>
[posted and mailed to Andrew Spiers]
Tad McClellan wrote:
>
> Andrew Spiers (andrew.spiers@virgin.net) wrote:
> : for $name1 (sort { $temp{$a} cmp $temp{$b} } keys %total) {
>
> cmp compares strings.
>
> <=> compares numbers.
True, but...
> The values in %temp are numbers.
What values in %temp? %temp is never populated in the code he posted.
Which is probably why it isn't working... ;-)
> (worthless choice of name there, %count or
> something that has some relationship to what is
> stored in it is a Good Idea.
> )
He probably meant to say $total{$a}, using the same hash he just got
the keys from.
Chipmunk
------------------------------
Date: Sat, 24 Jan 1998 11:07:18 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Survival Of perl
Message-Id: <ebohlmanEnAC87.8FA@netcom.com>
Aamer Nazir <nazira@cadvision.com> wrote:
: I have a question which some people would consider 'dumb, but it is not.I
: want to ask all of you people that what is the FUTURE of perl.I mean with
: the coming of NT servers and Softwares like FrontPage ,is perl going to
: survive.I am asking this question because I want to learn this language but
: first of all I would like to know what you people think about the language
: and what are its applications.
The majority of uses of Perl are in areas unrelated to CGI scripting.
Perl existed for several years before there even *was* such a thing as
CGI scripting. Improvements in Web servers will probably result in less
need to write custom CGI scripts, but won't have any effect on all the
other things people use Perl for.
------------------------------
Date: 24 Jan 1998 12:06:17 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Survival Of perl
Message-Id: <6ad729$g8f@panix.com>
In <34C98F5D.1CB82731@doitnow.com> "John C. Quillan" <quillan@doitnow.com> writes:
>As far as a language goes: You can argue back and forth about
>programming language issues but what I can say I like about
>perl is that it is PRATICAL. It can get quite a few jobs
>done, done well, and done quickly.
"Perl makes easy jobs easy, and hard jobs possible."
--
Clay Irving <clay@panix.com> I think, therefore I am. I think?
http://www.panix.com/~clay/
------------------------------
Date: Sat, 24 Jan 1998 16:07:54 GMT
From: George Cyriac <gcyriac@internetmci.com>
Subject: typeglob?
Message-Id: <34CA120E.27402122@internetmci.com>
--
Can anyone explain to me what a typeglob does(*)? I have programming
perl but I still can't understand?
What is the difference between:
&search(@words);
and
&search(*words);
?
I have used a typeglob when using cgi-lib.pl, but I don't know the
difference?
------------------------------------------------------------
http://www.serve.com/gcyriac/
George Cyriac Bayweb designs
gcyriac@internetmci.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 1720
**************************************