[24212] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6404 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 15 03:05:47 2004

Date: Thu, 15 Apr 2004 00:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 15 Apr 2004     Volume: 10 Number: 6404

Today's topics:
    Re: Changing from C thought to Perl <jwillmore@remove.adelphia.net>
    Re: Changing from C thought to Perl <uri.guttman@fmr.com>
    Re: Changing from C thought to Perl <mgjv@tradingpost.com.au>
    Re: eval running external script <jwillmore@remove.adelphia.net>
    Re: eval running external script <shailesh@nothing.but.net>
    Re: if someone can give me an example of RowCount metho <jwillmore@remove.adelphia.net>
    Re: Many filename arguments: EOF in "while(@slurp=<>){. <fma@doe.carleton.ca>
    Re: Many filename arguments: EOF in "while(@slurp=<>){. <jwillmore@remove.adelphia.net>
    Re: Two mini-golfish problems <uri@stemsystems.com>
    Re: Two mini-golfish problems <tassilo.parseval@rwth-aachen.de>
    Re: use of uninitialised value <tore@aursand.no>
    Re: use of uninitialised value <cenxnfu@rpr.nevmban.rqh>
    Re: use of uninitialised value <uri@stemsystems.com>
    Re: use of uninitialised value <uri@stemsystems.com>
    Re: Variables in an array (Cosmic Cruizer)
    Re: Variables in an array <cenxnfu@rpr.nevmban.rqh>
    Re: Variables in an array <uri@stemsystems.com>
    Re: Variables in an array <tore@aursand.no>
    Re: Variables in an array (Cosmic Cruizer)
    Re: Variables in an array <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 15 Apr 2004 00:29:51 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Changing from C thought to Perl
Message-Id: <pan.2004.04.15.04.29.45.620092@remove.adelphia.net>

On Wed, 14 Apr 2004 19:26:35 +0000, Rob Perkins wrote:

> James Willmore <jwillmore@remove.adelphia.net> wrote:
> 
>>On Wed, 14 Apr 2004 02:13:10 +0000, Rob Perkins wrote:
>>
>>> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
>>
>>[ ... ]
>>
>>> Side effects? I've already run into one: regex's don't behave the same
>>> on every platform. Side effects aren't a bad thing per se. Unless you
>>> want cross platform capability. Then you're screwed.
>>
>>And *where* did you read this?  I've *never* had an issue with regular
>>expressions across platforms.
> 
> I didn't read it. I lived it. See the "Tough (for me) regex case"
> thread. 
> 
> It's not a big deal. And as I've pointed out, it was a bad example. 

Yes, it is a lousy example - because the platform doesn't come into play. 
You just had a tough time with regular expressions in the referenced
thread :-)  Again - based upon the *language* used, not regular
expressions themselves.

I'd rather comment on your comments than let it slide.  Some newbie might
find it to be a true statement - and it is not.  You can use the same reg
ex, in Perl, *without* worrying about what platform you're running the
script on.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Ideas don't stay in some minds very long because they don't like
 solitary confinement. 
 


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

Date: 14 Apr 2004 13:45:11 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Changing from C thought to Perl
Message-Id: <siscy8oy78t4.fsf@tripoli.fmr.com>

>>>>> "AQ" == Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com> writes:

  AQ> Rob Perkins wrote:
  >> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
  >> 
  >>> Global variables are not a bad thing per se.  Side effects are not a bad
  >>> thing per se.

  >> No, not a bad thing, per se. Unless you need/want to share your code.

  AQ> I agree with most of what you say, but sometimes you can't help
  AQ> it. There are programs that are very difficult to write without global
  AQ> vars, like GUIs for example. Here, a program sits waiting for the user
  AQ> to do something, and has to react accordingly. It is extremely
  AQ> difficult to bypass using global vars, and in fact global vars make
  AQ> the program much simpler and easier to maintain.

you are both missing the important point. programs and modules are
different animals. programs can use globals since they are a single
image and not shared (sharing with threads inside is another
story). modules which use globals for certain kinds of storage will not
work when threaded or shared in other ways. but even modules can and
need to have globals for other reasons so ruling them out is bad as well.

  >> Side effects? I've already run into one: regex's don't behave the same
  >> on every platform.

  AQ> Care to give an example where a Perl regexp works differently on two
  AQ> different platforms, assuming of course you are using the same Perl
  AQ> version.

he has no clue about regexes so just ignore that part. but then he whole
attitude makes me ignore his posts.

uri


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

Date: 15 Apr 2004 06:59:02 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Changing from C thought to Perl
Message-Id: <slrnc7scll.7k7.mgjv@verbruggen.comdyn.com.au>

On Wed, 14 Apr 2004 23:51:32 GMT,
	Rob Perkins <rob_perkins@hotmail.com> wrote:
> Paul Lalli <ittyspam@yahoo.com> wrote:

>>They are not.  What you are terming a 'platform' of ".NET" has
>>nothing at all to do with Perl.
> 
> Sure it does. Perl behaves consistently across platforms, with similar
> services and a similar paradigm. Since it's interpreted/JIT-ed stuff,
> that means there is an execution engine. 
> 
> In the context of Java or .NET's CLR, that makes Perl5 a "platform",
> by a definition you are not using, but I am.

And once again, you show the Humpty Dumpty attitude that is at the
core of most of the verbosity in this thread.

Martien
-- 
                        | `When I use a word,' Humpty Dumpty said, 
Martien Verbruggen      | in rather a scornful tone, `it means just 
Trading Post Australia  | what I choose it to mean -- neither more   
                        | nor less.'


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

Date: Thu, 15 Apr 2004 01:26:09 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: eval running external script
Message-Id: <pan.2004.04.15.05.26.00.801192@remove.adelphia.net>

On Wed, 14 Apr 2004 23:10:29 +0000, Shailesh wrote:

>> You want to catch the external program's stderr (and probably stdout too).
>> See "perldoc perlipc" for how to do that.  Also look at the module
>> IPC::Open2.
>> 
>> Reading the script in a string and executing it is what "do FILE"
>> does.  That is another possibility.
>> 
> 
> I can't do file descriptor redirection, like it says here:
[ URL snipped ]
> because my script needs to run on windows and linux.  Open2 also only 
> works on Unix systems.  I think I will try eval { do 'run_task.pl'; };
> 
> c:\Shailesh> perl -e "do something or die shamefully"
> shamefully at -e line 1.
> 
> c:\Shailesh>

You *do* realize that the URL you referenced is an *illegal* copy of an
O'Reilly book, right?

And ... you could look over IPC::Run
(http://search.cpan.org/~rbs/IPC-Run-0.78/lib/IPC/Run.pm).

And ... you could look over the document I referenced in my previous post
:-) 
(http://www.perldoc.com/perl5.8.0/pod/perlfaq8.html#How-can-I-capture-STDERR-from-an-external-command-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Chemicals, n.:  Noxious substances from which modern foods are
 made. 
 


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

Date: Thu, 15 Apr 2004 06:33:03 GMT
From: Shailesh <shailesh@nothing.but.net>
Subject: Re: eval running external script
Message-Id: <z0qfc.16033$B%4.3162@fe2.columbus.rr.com>

> You *do* realize that the URL you referenced is an *illegal* copy of an
> O'Reilly book, right?
> 
> And ... you could look over IPC::Run
> (http://search.cpan.org/~rbs/IPC-Run-0.78/lib/IPC/Run.pm).
> 
> And ... you could look over the document I referenced in my previous post
> :-) 
> (http://www.perldoc.com/perl5.8.0/pod/perlfaq8.html#How-can-I-capture-STDERR-from-an-external-command-)
> 

Not until you told me.  I noticed something funny about how useful it 
was for something on the Internet, and that the same info wasn't at 
the o'reilly site, but it just didn't register.  Everything found 
through Google is right, isn't it?

I own Perl in a Nutshell and the Perl black book, but these are not 
helping me any for this task.  That Run module has some Win32 issues, 
and it is too much docs to read for something so simple.  Anyway, I 
changed my script to simple do FILE, and it seems to do what I want, 
except that now I have to figure out how to send the parameter I was 
previously passing on the command line.

-----------------------------
task_scheduler.pl
 ------------------------------
#!/usr/bin/perl -w
$retval = do("run_task.pl");
if(defined $retval) {
         print "retval: ".$retval."\n";
}
print "do returned: ".$@."\n";
 ------------------------------

 ------------------------------
OUTPUT of task_scheduler.pl
 ------------------------------
do returned: Illegal division by zero at run_task.pl line 5.

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

Though this worked, the version below does not work, even though your 
link says: "With system(), both STDOUT and STDERR will go the same 
place as the script's STDOUT and STDERR."  God I hate perl

eval {
$retval = system("perl run_task.pl");
};
if($@) {
         print "system returned: ".$@."\n";
}

OUTPUT:
Illegal division by zero at run_task.pl line 5.


I guess if all else fails, I'll turn the run_task script into a 
module, read it in as a string, and then eval it.


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

Date: Thu, 15 Apr 2004 01:35:54 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: if someone can give me an example of RowCount method of Win32::odbc
Message-Id: <pan.2004.04.15.05.35.48.909234@remove.adelphia.net>

On Tue, 13 Apr 2004 18:44:52 +0800, Wang Qi wrote:

> i want use this method to get the row count of a table named "SNP" from a
> sql server database with the odbc DSN "control" and user "loyata" passwd
> "asdf". From the cpan I cannot find the example of this method, so please
> help me if you have used it.

You've read the documentation for the DBI module ....
http://search.cpan.org/~timb/DBI-1.42/DBI.pm

 ... and the documentation for the DBD::ODBC module
http://search.cpan.org/~jurl/DBD-ODBC-1.09/ODBC.pm

Post what you have so far and maybe we can help :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Think twice before speaking, but don't say "think think click
 click". 
 


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

Date: 15 Apr 2004 05:17:45 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Re: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <407E1AF2.37AEECF0@doe.carleton.ca>

Tad McClellan wrote:
> 
> Fred Ma <fma@doe.carleton.ca> wrote:
> 
> > I wish there was an index that tells you what perldoc sections to
> > look in.
> 
> I make my own index:
> 
>    perldoc -l perlfunc   # find out where the .pods are
>    cd .../pod            # go to where the pods are
>    perl -ne 'print "$ARGV: $_" if /^=/' *.pod >all.heads
>    (or: grep ^= *.pod >all.heads)
> 
> Then I search it with grep:
> 
>    grep SOMETHING all.heads
> 
> or with grep written in Perl:
> 
>    perl -ne 'print if /SOMETHING/' all.heads


Tad,

Thanks for the tip.  I still believe, however, that a
conventional hyperlinked index would be invaluable to
people getting into Perl.

Fred
-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6


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

Date: Thu, 15 Apr 2004 01:45:23 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <pan.2004.04.15.05.45.18.24723@remove.adelphia.net>

On Thu, 15 Apr 2004 05:17:45 +0000, Fred Ma wrote:

> Tad McClellan wrote:
>> 
>> Fred Ma <fma@doe.carleton.ca> wrote:
>> 
>> > I wish there was an index that tells you what perldoc sections to
>> > look in.
>> 
>> I make my own index:
>> 
>>    perldoc -l perlfunc   # find out where the .pods are
>>    cd .../pod            # go to where the pods are
>>    perl -ne 'print "$ARGV: $_" if /^=/' *.pod >all.heads
>>    (or: grep ^= *.pod >all.heads)
>> 
>> Then I search it with grep:
>> 
>>    grep SOMETHING all.heads
>> 
>> or with grep written in Perl:
>> 
>>    perl -ne 'print if /SOMETHING/' all.heads

> Thanks for the tip.  I still believe, however, that a
> conventional hyperlinked index would be invaluable to
> people getting into Perl.

Use the ActiveState distro of Perl for Windows :-)  It comes with HTML
pages of all the documentation.  Not sure if it's the same for the other
ActiveState offerings for other platforms.

And ... as always ... you could visit http://perldoc.com/ :-)

OTOH, Tad's code is pretty slick :-)  I like it and will start using it
 ... even if you won't :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 186,282 miles per second:  It isn't just a good idea, it's the
 law! 
 


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

Date: Thu, 15 Apr 2004 04:17:52 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Two mini-golfish problems
Message-Id: <x71xmpc1sf.fsf@mail.sysarch.com>

>>>>> "B" == Bill  <wherrera@lynxview.com> writes:


  B> Remember: succint, maintainable, fast. Choose 2 of 3 :)

how about correct?

  B> $x = 'fubar';
  B> $x=~s/(..)/$1\n/g;print $x;

what happens to the 'r'?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 15 Apr 2004 06:48:22 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Two mini-golfish problems
Message-Id: <c5lb7m$32i2h$1@ID-231055.news.uni-berlin.de>

Also sprach Bill:

> J Krugman wrote:
> 
>> OK, here's a little problem that I'd like to propose in the Perl
>> golf (mini-golf?) vein.
>> 
> 
>> Given a string $x that we may assume contains no newline characters,
>> split it into chunks of $n characters long separated my newlines.
>> E.g. if $n == 2,
>> 
>>                'fu'
>>   'fubar' ---> 'ba'
>>                'r'
>> 
>> What's the most succinct Perl to achive this end-result?
> 
> Remember: succint, maintainable, fast. Choose 2 of 3 :)
> 
> anyhow...
> 
> $x = 'fubar';
> $x=~s/(..)/$1\n/g;print $x;

That should be:

    $x=~s/(..?)/$1\n/g;

Otherwise it omits the last newline for words of uneven length.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 15 Apr 2004 06:22:14 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: use of uninitialised value
Message-Id: <pan.2004.04.15.04.17.06.208903@aursand.no>

On Wed, 14 Apr 2004 20:39:10 -0700, Cognition Peon wrote:
> I am getting desried output for the following piece, but -w switch to perl
> [...]

Just a recommendation:  If you're using Perl 5.6.1 (or newer), you should
drop '-w' and use 'use warnings' instead;

  #!/usr/bin/perl
  #
  use strict;
  use warnings;

> [...]
> is reporting that 'if />.*/' in the code uses uninitialized value. The
> input file follows. I also tried another combination of if statement, but
> the error still persists. 'if /^(>.*)/' accessing the match from $1.
> 
> while(<FILE>) {
>         my ($header, ) = ();

Hmm.  What is this?

>         next if /^$/;

And this?  Are you trying to match empty lines?  No need for a regular
expression for that.

>         chomp;

You should try to do this a immediate as possible.

>         if (/>.*/) { # Use of uninitialized value here

Have in mind that the warning might refer to something within the scope of
that 'if' statement.

>                 $header = $&;

Do you _really_ need to use '$&'?  Take a look at 'perldoc perlvar':

    [...]
    The use of this variable anywhere in a program imposes a considerable
    performance penalty on all regular expression matches.  See "BUGS".

>                 $bin = (split('[_-]', $header))[1];

Maybe it's just me, but I don't see the string '[_-]' in the data you're
reading?  What are you _really_ trying to do?  Match the part of the
string _after_ the '[C/T]' string?

>                 $fasta{$header} = $_;

'$header' will always be undefined here.  You never set it to something
withing that scope.

If so (untested and might not even do what you want it to):

  while ( <FILE> ) {
      chomp;
      next unless ( length );

      if ( m,\[C/T\](.*)$, ) {
          push( @{$bins{$1}}, $_ );
      }
      else {
          # Not sure what you really want to achieve/do here
      }
  }


-- 
Tore Aursand <tore@aursand.no>
"The purpose of all war is ultimately peace." -- Saint Augustine


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

Date: Wed, 14 Apr 2004 21:15:45 -0700
From: Cognition Peon <cenxnfu@rpr.nevmban.rqh>
Subject: Re: use of uninitialised value
Message-Id: <Pine.GSO.4.50.0404142114590.19603-100000@ece2.ece.arizona.edu>

8:39pm, IP packets from Cognition Peon delivered:

>
> I am getting desried output for the following piece, but -w switch to perl
> is reporting that 'if />.*/' in the code uses uninitialized value. The
> input file follows. I also tried another combination of if statement, but
> the error still persists. 'if /^(>.*)/' accessing the match from $1.
>
>
> while(<FILE>) {
>         my ($header, ) = ();

initializing $header for every line in the file is causing the problem.
just figured it..

>         next if /^$/;
>         chomp;
>
>         if (/>.*/) { # Use of uninitialized value here
>                 $header = $&;
>                 $bin = (split('[_-]', $header))[1];
>                 push @{$bins{$bin}}, $header;
>         } else {
>                 $fasta{$header} = $_;
>         }
> }
> close(FILE);
>
> >uTSLPxov-bin3-005614
> TAATTTAGAAAAAATCATGGCCCCACATTTTGTCAAGGATTCTTACAAGTGATATTCAAATATCTAATCTAAAATGATTATCTAGAAATTGGCACATTCTAAGTGTGCAGATGCTGATGAGGAGCAGGTATTGATAGACAGCGCGTTATG[C/T]GTCAAAGGATGTCTATCCTTTGCTAAAGTGTTACTCTGACTATGCTGTAAAAAGCAGGAGGTAAGAGCTTAAGAAAGAGGAGTAAAAGAGATAATTCTCATGAGATAAACTCTAAGGATTGATGCTGTGCTCCAGGTCTCTCCAGTGTTT
>
> >uTSLPxov-bin4-005119
> AAAGAGCCCGTAGGCGTTTAGGTGTTATATAGTGCAGCCAGAAAGCTCTGGAGCATCAGGGAGACTCCAACTTAAGGCAACAGCATGGGTGAATAAGGGCTTCCTGTGGACTGGCAATGAGAGGCAAAACCTGGTGCTTGAGCACTGGCC[C/T]CTAAGGCAGGCCTTACAGATCTCTTACACTCGTGGTGGGAAGAGTTTAGTGTGAAACTGGGGTGGAATTGGGTGTCCACGTATGTTCCCTTTTGCCTTACTATATGTTCTGTCAGTTTCTTTCAGGAAAATCTTCATCTTACAACTTGTA
> >uTSLPxov-bin4-006317
> ACCCTCTTTGTCCTATTTTTCTTTCTTCCAGACCAAAAGTACCGAGTTCAACAACACCGTCTCTTGTAGCAATCGGGTGAGTAGAGAGTTCAGTGCTGCTGGCTTTCTCCAGGGAGACGCCAGGCATTTTGGAGAGGGAGTATCCTGCTA[C/T]GTGCAGAACTCCGAGAGGTGCCTGGGCTCCGGGACGCCGCCGCCGGGGGAAAGGGGACATCTGGGCTGTCAGAGCGGGGCTGCGCCTAGCTTGGGACAACACTTCTGTTCCAATTTAGGGAGAGGAAGTCTCTATCCGGAGGAAAGGCAA
>
>
>
>
>

-- 
echo cenxnfu@rpr.nevmban.rqh | perl -pe 'y/a-z/n-za-m/'

Life is a bridge, enjoy while crossing but don't build
a castle on it.				 - Upanishads
-------------------------------------
Printed using 100% recycled electrons


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

Date: Thu, 15 Apr 2004 04:31:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: use of uninitialised value
Message-Id: <x7vfk1amld.fsf@mail.sysarch.com>

>>>>> "CP" == Cognition Peon <cenxnfu@rpr.nevmban.rqh> writes:

  CP> I am getting desried output for the following piece, but -w switch to perl
  CP> is reporting that 'if />.*/' in the code uses uninitialized value. The
  CP> input file follows. I also tried another combination of if statement, but
  CP> the error still persists. 'if /^(>.*)/' accessing the match from $1.


  CP> while(<FILE>) {
  CP>         my ($header, ) = ();

huh? my $header is fine.

  CP>         next if /^$/;
  CP>         chomp;

  CP>         if (/>.*/) { # Use of uninitialized value here

are you sure about that line number? assuming you read a line into $_,
that is matching $_ which is defined. and you don't seem to be reading
in the data line after the header line.

  CP>                 $header = $&;

don't use $&. make an explicit grab and use $1.

			my( $header ) = />(.+)/ ;

  CP>                 $bin = (split('[_-]', $header))[1];

split takes a regex so mark that with //. and why the convoluted code
there?

		($bin) = $header =~ /-(\w+)-/ ;


  CP>                 push @{$bins{$bin}}, $header;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 15 Apr 2004 04:33:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: use of uninitialised value
Message-Id: <x7smf5amh7.fsf@mail.sysarch.com>

>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:

  >> $bin = (split('[_-]', $header))[1];

  TA> Maybe it's just me, but I don't see the string '[_-]' in the data you're
  TA> reading?  What are you _really_ trying to do?  Match the part of the
  TA> string _after_ the '[C/T]' string?

that is the same as /[_-]/. the first arg to split is always a regex,
even if it looks like a string. the special case of split ' ' is an
exception.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 15 Apr 2004 04:09:49 GMT
From: XXjbhuntxx@white-star.com (Cosmic Cruizer)
Subject: Re: Variables in an array
Message-Id: <Xns94CBD73E044E0ccruizermydejacom@64.164.98.49>

"Jürgen Exner" <jurgenex@hotmail.com> wrote in <uPnfc.34506$F9.1129
@nwrddc01.gnilink.net>:

>use strict;
>use warnings;
>my %fruit = (sm1 => 'apple',
>        sm2 => 'orange',
>        sm3 => 'lemon');
>my @sm_list = qw(sm1 sm2 sm3);
>foreach (@sm_list) {
>   print $fruit{$_};
>}
>
>

Thanks Jürgen. As hard as I try, the various data structures are a challenge 
for me. I was trying to use the Perl Cookbook to come up with a solution, 
but finally gave up.

Thanks again.


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

Date: Wed, 14 Apr 2004 20:52:28 -0700
From: Cognition Peon <cenxnfu@rpr.nevmban.rqh>
Subject: Re: Variables in an array
Message-Id: <Pine.GSO.4.50.0404142050150.19603-100000@ece2.ece.arizona.edu>



> I would like to create something similar to the following:
>
> my $sm1 = "apple";
> my $sm2 = "orange";
> my $sm3 = "lemon";
>
> my @sm_list = qw($sm1 $sm2 $sm3);
>
> foreach (@sm_list) {
>   print $_;
    print "$_ ";

> }
>
> I would like the output to be: apple orange lemon
>
> I understand why this does not work, but is there some way I can change the
> print statement to print get my desired output?
>

The following print statement can be used instead of foreach

print @sm_list;

print statement will join list of elements with ' ' before printing.

-- 
echo cenxnfu@rpr.nevmban.rqh | perl -pe 'y/a-z/n-za-m/'

Life is a bridge, enjoy while crossing but don't build
a castle on it.				 - Upanishads
-------------------------------------
Printed using 100% recycled electrons


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

Date: Thu, 15 Apr 2004 04:21:40 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Variables in an array
Message-Id: <x7y8oxan1o.fsf@mail.sysarch.com>

>>>>> "CP" == Cognition Peon <cenxnfu@rpr.nevmban.rqh> writes:

  >> I would like to create something similar to the following:
  >> 
  >> my $sm1 = "apple";
  >> my $sm2 = "orange";
  >> my $sm3 = "lemon";
  >> 
  >> my @sm_list = qw($sm1 $sm2 $sm3);
  >> 
  >> foreach (@sm_list) {
  >> print $_;
  CP>     print "$_ ";

  >> }

  CP> The following print statement can be used instead of foreach

  CP> print @sm_list;

and how does that solve the OP's problem?

  CP> print statement will join list of elements with ' ' before printing.

and that is wrong on 2 levels. print @foo will print nothing between its
elements. and if you do want something you set $,.

as for the OP, learn perl data structures. you said they are too hard
but the path you are going down (symrefs) is even harder. your choice.

read these:

perldoc perlreftut
perldoc perldsc
perldoc perllol

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 15 Apr 2004 06:22:14 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Variables in an array
Message-Id: <pan.2004.04.15.04.21.57.826100@aursand.no>

On Thu, 15 Apr 2004 03:47:05 +0000, Cosmic Cruizer wrote:
> my $sm1 = "apple";
> my $sm2 = "orange";
> my $sm3 = "lemon";
> 
> my @sm_list = qw($sm1 $sm2 $sm3);
> 
> foreach (@sm_list) {
>   print $_;
> }
> 
> I would like the output to be: apple orange lemon
> 
> I understand why this does not work, but is there some way I can change the 
> print statement to print get my desired output?

Read the documentation:

  perldoc perlop

It says that 'qw( ... )' denotes a word list which _won't_ get
interpolated, thus it'll just hold whatever - literally - you insert into
it.

You might be better of with this solution:

  my @sm_list = ('apple', 'orange', 'lemon');
  print join( "\n", @sm_list );


-- 
Tore Aursand <tore@aursand.no>
"First get your facts; then you can distort them at your leisure." --
 Mark Twain


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

Date: Thu, 15 Apr 2004 05:46:33 GMT
From: XXjbhuntxx@white-star.com (Cosmic Cruizer)
Subject: Re: Variables in an array
Message-Id: <Xns94CBE7A45B52Bccruizermydejacom@64.164.98.49>

Uri Guttman <uri@stemsystems.com> wrote in 
<x7y8oxan1o.fsf@mail.sysarch.com>:

>>>>>> "CP" == Cognition Peon <cenxnfu@rpr.nevmban.rqh> writes:
>
>  >> I would like to create something similar to the following:
>  >> 
>  >> my $sm1 = "apple";
>  >> my $sm2 = "orange";
>  >> my $sm3 = "lemon";
>  >> 
>  >> my @sm_list = qw($sm1 $sm2 $sm3);
>  >> 
>  >> foreach (@sm_list) {
>  >> print $_;
>  CP>     print "$_ ";
>
>  >> }
>
>  CP> The following print statement can be used instead of foreach
>
>  CP> print @sm_list;
>
>and how does that solve the OP's problem?
>
>  CP> print statement will join list of elements with ' ' before printing.
>
>and that is wrong on 2 levels. print @foo will print nothing between its
>elements. and if you do want something you set $,.
>
>as for the OP, learn perl data structures. you said they are too hard
>but the path you are going down (symrefs) is even harder. your choice.
>
>read these:
>
>perldoc perlreftut
>perldoc perldsc
>perldoc perllol
>
>uri
>

Uri, I agree with what you say about learning. Unfortunately, there are some 
things that I have difficulty in learning. The good thing is, I generally 
only ask a specific type of question once, then can continue to use the 
answer I get for later projects. Each time I get an answer I copy it to my 
folder of Perl snippits. That is exactly what I did with the answer that jue 
posted. I realized it might appear like a hard way to learn, but it seems to 
be the most productive way I am able to make progress.

Thanks


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

Date: Thu, 15 Apr 2004 06:25:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Variables in an array
Message-Id: <x765c1ahb5.fsf@mail.sysarch.com>

>>>>> "CC" == Cosmic Cruizer <XXjbhuntxx@white-star.com> writes:

  CP> The following print statement can be used instead of foreach
  >> 
  CP> print @sm_list;
  >> 
  >> and how does that solve the OP's problem?

you didn't answer that question.


  CC> Uri, I agree with what you say about learning. Unfortunately,
  CC> there are some things that I have difficulty in learning. The good
  CC> thing is, I generally only ask a specific type of question once,
  CC> then can continue to use the answer I get for later projects. Each
  CC> time I get an answer I copy it to my folder of Perl snippits. That
  CC> is exactly what I did with the answer that jue posted. I realized
  CC> it might appear like a hard way to learn, but it seems to be the
  CC> most productive way I am able to make progress.

you are solving problems with fixed answers which is very bad in the
programming world. you need to learn how to learn and also be more
flexible. one solution is never right for all problems. a good rule to
learn is solve in the general and apply in the specific. a library of
perl snippets means you are not understanding the code and you are just
copying it. you should understand the code well enough to be able to
recreate the snippet on demand and customize it to the current
situation. i can't help you learn better but i can tell you of bad ways
to code and that is one of them.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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


Administrivia:

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

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

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

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

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


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


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