[23569] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5776 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 10 18:05:45 2003

Date: Mon, 10 Nov 2003 15:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 10 Nov 2003     Volume: 10 Number: 5776

Today's topics:
    Re: command line text processing.. (Tad McClellan)
        dates <moliverius@w-link.net>
    Re: dates <xx087@freenet.carleton.ca>
    Re: dates <uri@stemsystems.com>
        globals and while <perl@my-header.org>
    Re: globals and while <uri@stemsystems.com>
    Re: globals and while <xxala_qumsiehxx@xxyahooxx.com>
    Re: globals and while <uri@stemsystems.com>
    Re: Interaction between two strings (Anno Siegel)
    Re: Newbie question - create a file <bmb@ginger.libs.uga.edu>
        Perl help <lmbylsma@psych.upenn.edu>
    Re: Perl help (Tad McClellan)
    Re: roundup to 60 or 70 or 50 (offtopic) (Antoine Adams)
    Re: simplify this if loop <perl@my-header.org>
    Re: simplify this if loop <krahnj@acm.org>
    Re: Sort array of objects using a method <uri@stemsystems.com>
    Re: Style question: map versus foreach <go@away.spam>
    Re: Style question: map versus foreach <abigail@abigail.nl>
        Syntax question <moliverius@w-link.net>
    Re: Syntax question <noreply@gunnar.cc>
    Re: Syntax question (Tad McClellan)
    Re: Tool to embed images (or other binaries)  in your P <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 10 Nov 2003 16:27:54 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: command line text processing..
Message-Id: <slrnbr047a.cmu.tadmc@magna.augustmail.com>

Jim Carter <carterave@yahoo.com> wrote:

> I need a commmand line perl code to strip off every thing that
> starts after colon


   perl -pe 's/:.*//s'


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


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

Date: Mon, 10 Nov 2003 12:56:45 -0500
From: Matt Oliverius <moliverius@w-link.net>
Subject: dates
Message-Id: <vqvtge24357tb7@corp.supernews.com>


I'm trying to grab the date in a current script I am using. However, when I 
assign

$date = `date`;

I get time in UTC format.  How would I change the assignment above so that 
I can get time in Pacific Standard Time?




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

Date: 10 Nov 2003 20:55:08 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: dates
Message-Id: <slrnbqvuqm.lbp.xx087@smeagol.ncf.ca>

Matt Oliverius <moliverius@w-link.net> wrote:
>  $date = `date`;
>  
>  I get time in UTC format.  How would I change the assignment above so that 
>  I can get time in Pacific Standard Time?

$date = `env TZ=PST date`;

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Mon, 10 Nov 2003 21:06:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: dates
Message-Id: <x7y8uoylur.fsf@mail.sysarch.com>

>>>>> "GJ" == Glenn Jackman <xx087@freenet.carleton.ca> writes:

  GJ> Matt Oliverius <moliverius@w-link.net> wrote:
  >> $date = `date`;
  >> 
  >> I get time in UTC format.  How would I change the assignment above so that 
  >> I can get time in Pacific Standard Time?

  GJ> $date = `env TZ=PST date`;

why fork off a process (even if the OP did)?

perl -le 'print scalar localtime'
Mon Nov 10 16:00:47 2003

perl -le '$ENV{TZ}="PST" ; print scalar localtime'
Mon Nov 10 21:01:07 2003

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: Mon, 10 Nov 2003 20:12:47 +0100
From: Matija Papec <perl@my-header.org>
Subject: globals and while
Message-Id: <l1mvqvk2lu60rlnsuptitah8adn30i55ml@4ax.com>


use strict;
my $x = 3;
print "$y\n" while my $y = $x--;

Why does perl want to use global $y; can someone point me to relevant rtfm?
:)


-- 
Matija


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

Date: Mon, 10 Nov 2003 19:25:59 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: globals and while
Message-Id: <x7fzgw10vt.fsf@mail.sysarch.com>

>>>>> "MP" == Matija Papec <perl@my-header.org> writes:

  MP> use strict;
  MP> my $x = 3;
  MP> print "$y\n" while my $y = $x--;

  MP> Why does perl want to use global $y; can someone point me to relevant rtfm?
same reason why you can't refer to a my $sub from inside the closure
assigned to it:

	my $sub = sub { $sub->( blah ) }

$sub isn't declared yet so the $sub inside the closure refers to a
global (or earlier lexical) $sub. your code has the same problem,
refering to a lexical declared the same statement.

the main reason for this is so you can do stuff like:

my $foo ;

{
# this assigns the value of the current foo to the new lexical foo
# if your code worked, then this would not be possible.

	my $foo = $foo ;

	mung with $foo
}

# print untouched foo
print $foo ;

perldoc -f my refers you to the private variables section of perlsub
which does cover this point.

     The declared variable is not introduced (is not visible)
     until after the current statement.  Thus,

         my $x = $x;

     can be used to initialize a new $x with the value of the old
     $x, and the expression

         my $x = 123 and $x == 123

     is false unless the old $x happened to have the value "123".



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: Mon, 10 Nov 2003 19:36:58 GMT
From: "Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: globals and while
Message-Id: <uNRrb.2944$dK6.2525@newssvr14.news.prodigy.com>

"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7fzgw10vt.fsf@mail.sysarch.com...
> >>>>> "MP" == Matija Papec <perl@my-header.org> writes:
>
>   MP> use strict;
>   MP> my $x = 3;
>   MP> print "$y\n" while my $y = $x--;
>
>   MP> Why does perl want to use global $y; can someone point me to
relevant rtfm?
> same reason why you can't refer to a my $sub from inside the closure
> assigned to it:
>
> my $sub = sub { $sub->( blah ) }
>
> $sub isn't declared yet so the $sub inside the closure refers to a
> global (or earlier lexical) $sub. your code has the same problem,
> refering to a lexical declared the same statement.

But I thought that the OP's code was symantically identical to the
following:

  use strict;
  my $x = 3;
  while (my $y = $x--) {
    print "$y\n";
  }

and this is perfectly fine. Why the difference in behaviour then?

--Ala




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

Date: Mon, 10 Nov 2003 19:44:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: globals and while
Message-Id: <x77k28101l.fsf@mail.sysarch.com>

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

  >> >>>>> "MP" == Matija Papec <perl@my-header.org> writes:
  >> 
  MP> my $x = 3;
  MP> print "$y\n" while my $y = $x--;

  AQ> But I thought that the OP's code was symantically identical to the
  AQ> following:

  AQ>   use strict;
  AQ>   my $x = 3;
  AQ>   while (my $y = $x--) {
  AQ>     print "$y\n";
  AQ>   }

  AQ> and this is perfectly fine. Why the difference in behaviour then?

how are those the same? the OP's code was a single statement, yours is a
while with a block. in the former, my $y means $y is not visible until
the next statement. in your code $y is visible to the code in the block.

the code make look similar but there is a major different in the scope
of $y.

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: 10 Nov 2003 20:06:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Interaction between two strings
Message-Id: <boor4d$5ig$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > gilgames wrote:
> 
> <snip>
> 
> > I still don't get it.  Yes, the code above would behave as you
> > describe. Now, what characters from what string do you want to use
> > as a parameter value in which way?
> > 
> > You really got to work on the way you present your problem.
> 
> "gilgames" seems not to be OP.

Oh, right.  For some reason I read the posting as an explanatory self-
followup, which it wasn't.  Apologies all 'round.

Anno


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

Date: Mon, 10 Nov 2003 15:43:32 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Newbie question - create a file
Message-Id: <Pine.A41.4.58.0311101540200.13850@ginger.libs.uga.edu>

On Mon, 10 Nov 2003, Master Web Surfer wrote:

> #!/usr/bin/perl -w
>
> $filename = "dogs.txt";
> open(GOLDEN,">$filename") or
>           die("Can't write \"$filename\" : $!\n");
> print GOLDEN "My dog is a golden retriever.\n";
> close GOLDEN;
>
> exit 0;
>

Don't forget:

use strict;

Regards,

Brad


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

Date: Mon, 10 Nov 2003 16:04:10 -0500
From: "Lauren M. Bylsma" <lmbylsma@psych.upenn.edu>
Subject: Perl help
Message-Id: <booufu$bkq3$1@netnews.upenn.edu>

I'm trying to learn Perl to anaylze some data and I am having trouble
getting started, so if someone could help me out that would be greatly
appreciated.  So I have a data file that looks something like this:


"INFORMATION"
"b2jun0302"
""
""
""
""
""

"SUMMARY"
"13" "Evt-" "correct" 1
"14" "Evt-" "incorrect" 1
"19" "Evt-" "rcor" 1
"20" "Evt-" "rincor" 1
"32" "Marker" "untitled"

"CHANNEL" "13"
"Evt-"
"No comment"
"correct"

3.92090
16.37657
19.26123
22.21257
25.54742

"CHANNEL" "14"
"Evt-"
"No comment"
"incorrect"

214.23345
238.11100
287.04997
379.90897
431.91602


What I want to do is take the numbers under Channel 13 and put them in an
array then Channel 14 in a separate array.  Then I want to add another
column to each.  For channel 13 I want this other column to contain all 1's.
For Channel 14 I want this column to contain all 0's.  Then I want to put
them together
into one big array and sort it by number from smallest to largest.

Please help :-)

-Lauren





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

Date: Mon, 10 Nov 2003 16:46:11 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl help
Message-Id: <slrnbr059j.cmu.tadmc@magna.augustmail.com>

Lauren M. Bylsma <lmbylsma@psych.upenn.edu> wrote:

> Subject: Perl help


Please put the subject of your post in the Subject of your post.

Have you seen the Posting Guidelines that are posted here frequently?


> What I want to do is take the numbers under Channel 13 and put them in an
> array then Channel 14 in a separate array.  Then I want to add another
> column to each.  


"column"?

What column?

I do not see any columns.

You would need a multi-dim array in order to have columns.


> For channel 13 I want this other column to contain all 1's.
> For Channel 14 I want this column to contain all 0's.  


I'll need to ignore that part of the specification, as I don't
understand what it means...


> Then I want to put
> them together
> into one big array and sort it by number from smallest to largest.


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

my @combined;
{  local $/ = '';  # enable paragraph mode
   while (<DATA>) {
      next unless /^"CHANNEL" "(\d+)"/;
      my @nums = split /\n/, scalar <DATA>;  # read the next para
      push @combined, @nums;
   }
}

print "$_\n" for sort { $a <=> $b } @combined;

__DATA__
"INFORMATION"
"b2jun0302"
""
""
""
""
""

"SUMMARY"
"13" "Evt-" "correct" 1
"14" "Evt-" "incorrect" 1
"19" "Evt-" "rcor" 1
"20" "Evt-" "rincor" 1
"32" "Marker" "untitled"

"CHANNEL" "13"
"Evt-"
"No comment"
"correct"

3.92090
16.37657
19.26123
22.21257
25.54742

"CHANNEL" "14"
"Evt-"
"No comment"
"incorrect"

214.23345
238.11100
287.04997
379.90897
431.91602
--------------------------------------


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


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

Date: 10 Nov 2003 13:17:25 -0800
From: antoine@nebula.nl (Antoine Adams)
Subject: Re: roundup to 60 or 70 or 50 (offtopic)
Message-Id: <d5716005.0311101317.35c1e5a7@posting.google.com>

> print "Just another Perl hacker,"

Ok ok.. thx guys.

3 solutions and all three work..
I liked them all and tested them all

Thx thx thx thx

Now I can continue playing with GD::Graph and mysql data uotput sorting :-)

----
A G-string fits better then a perl string


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

Date: Mon, 10 Nov 2003 20:12:46 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: simplify this if loop
Message-Id: <ihlvqvodt6q9q9t0b9igq095d853fjn89t@4ax.com>

X-Ftn-To: John W. Krahn 

"John W. Krahn" <krahnj@acm.org> wrote:
>This appears to produce the same output as your example:
>
>my $m = 2;
>sub avg { my $tot; $tot += $_ for @_; $tot / @_ }
>for ( my $i = $m - 1; my @group = @data[ $i - ( $m - 1 ), $i ], $i < @data; ++$i ) {

IMO this is terrifying, I know I always regret when wrote something like
that. ;)



-- 
Matija


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

Date: Mon, 10 Nov 2003 21:31:36 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: simplify this if loop
Message-Id: <3FB003B6.D964F79D@acm.org>

"John W. Krahn" wrote:
> 
> This appears to produce the same output as your example:
> 
> my $m = 2;
> sub avg { my $tot; $tot += $_ for @_; $tot / @_ }
> for ( my $i = $m - 1; my @group = @data[ $i - ( $m - 1 ), $i ], $i < @data; ++$i ) {
>     print $i + 1, "  ", $group[ -1 ], "  ", avg( @group ), "\n";
>     }

Oops, need to change the comma operator to a range operator.

my $m = 2;
sub avg { my $tot; $tot += $_ for @_; $tot / @_ }
for ( my $i = $m - 1; my @group = @data[ $i - ( $m - 1 ) .. $i ], $i < @data; ++$i ) {
    print $i + 1, "  ", $group[ -1 ], "  ", avg( @group ), "\n";
    }


John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 10 Nov 2003 19:15:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Sort array of objects using a method
Message-Id: <x7llqo11d0.fsf@mail.sysarch.com>

>>>>> "M" == Marcus  <bayrazone@web.de> writes:

  M> Hello, I'am a newbee in Perl and in Newsgroups. But I hope for some
  M> help.

  M> I have a array of Objekts and i want to sort these Objekts by using a
  M> Objektmethod.

  M> I tried this:
  M> certainly the Objektstore ist filled with Objekts !!!

  M> @unsortedObjektstore

  M> @sortedObjekts = sort {$unsortedObjektstore->getNumber() <=>
  M> $unsortedObjektstore->getNumber()} @unsortedObjektstore;

where did $unsortedObjektstore get its value? sort doesn't put it there.

  M> I thougt it works like an example in perldoc:
  M>     # sort numerically descending
  M>     @articles = sort {$b <=> $a} @files;

so do the same as sort. note that $a and $b are special variable that
sort uses to assign pairs of values to be compared. your code assumed
your own variable name which is wrong.

so use use $a and $b as the objects and call your methods like you did:

	@sortedObjekts = sort { $a->getNumber() <=> $b->getNumber()}
			@unsortedObjektstore;

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: Mon, 10 Nov 2003 19:27:46 GMT
From: "LaDainian Tomlinson" <go@away.spam>
Subject: Re: Style question: map versus foreach
Message-Id: <SERrb.109150$IA2.3873769@twister.southeast.rr.com>

"Abigail" wrote:
> LaDainian Tomlinson (go@away.spam) wrote on MMMDCCXXII September MCMXCIII
> in <URL:news:Jrvrb.91943$fl1.3981732@twister.southeast.rr.com>:
> ##  "Abigail" wrote:
> ## >
> ## > I'm curious, what made you think that map () in void context was bad
> ## > practice?
> ##
> ##  I guess I don't like discarding return values.  It seems like a bad
habit to
> ##  get into.  At least in this case, it could have easily been avoided
with a
> ##  solution like Roy's (printing the list returned by grep() or map()
rather
> ##  than printing in the map() itself).
>
> print returns a value, which is discarded in void context..
> Assignment returns a value, which is discarded in void context.
> s/// returns a value, which is discarded in void context.
> pop returns a value, which is discarded in void context.
> map returns a value, which is discarded in void context.

You are correct, and I know there are loads of others too, not just in Perl.

> Do you think that using any of these five operations in void context is
> bad practise? If not, could you indicate why using some operations in
> void context is fine, but map in void context is bad practise? Because
> I really fail to see what map has done to get this special status.

No, I don't (except for map() :-), and no, I can't.  It's simply a judgment
call in most cases whether or not to capture a return value.  _Everyone_
knows that you should always, yes *always*, check the return value of
open(), and close(), and system() and various other such functions with
"important" return values.  Failing to do so has a high probability of
affecting the way your code works.

However, most of the time you don't necessarily need to know the number of
substitutions made on a string by s/// or the success of the last print
operation, and sometimes you just need to pop the last value on an array.
In these cases, functions are the simplest way to perform such operations,
so the choice is either to capture the return value and do nothing with it,
or just ignore it altogether.  And it makes more sense to ignore it.  In my
example, there was an easy way to avoid discarding the return value while
still achieving the same behavior.  I _personally_ prefer to avoid returns
in void context when possible and plausible.  I can't quantify the
importance of return values or draw a line to separate the good ones from
the bad ones, but I still need to make a (possibly informed) decision
between a few different ways of doing something.

Which is why I asked in the first place, and I've gotten a lot of good
insight.  So thank you folks.

Brandan L.
--
bclennox AT eos DOT ncsu DOT edu



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/27/2003




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

Date: 10 Nov 2003 22:30:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Style question: map versus foreach
Message-Id: <slrnbr04b8.m62.abigail@alexandra.abigail.nl>

Darin McBride (dmcbride@naboo.to.org.no.spam.for.me) wrote on MMMDCCXXIII
September MCMXCIII in <URL:news:RKQrb.361373$6C4.143831@pd7tw1no>:
::  Abigail wrote:
::  
:: > Darin McBride (dmcbride@naboo.to.org.no.spam.for.me) wrote on MMMDCCXXIII
:: > September MCMXCIII in <URL:news:FRCrb.356754$pl3.261426@pd7tw3no>:
:: > __  Abigail wrote:
:: > __
:: > __  No, you're right.  I suppose you overlooked the "that's the concept"
:: > __  part of that paragraph.  Context rules in perl.  But that doesn't mean
:: > __  that context rules in the maintainer's head when trying to decipher
:: > __  what was written.
:: > 
:: > If you're going to assume the maintainer doesn't know basic concepts
:: > of Perl, all bets are off. Then one might want to avoid hashes and
:: > regexes too.
::  
::  True to a point.  However, there is no cleaner way to do hashes or
::  regexes.  There is a clearer way to do map in void context: foreach. 

But could you give an objective reason why foreach is "clearer" than
map (after defining what "clearer" is)? Or is it your own preference?
What makes foreach cleaner than while? Or is while cleaner than
foreach? Which one ought to go?  Or can we have foreach, for, while,
until, goto, and bare blocks, but not map in void context?

::  And that's the crux, too.  If there was no foreach, then it would be
::  obvious to all comers that map in void context is used for a particular
::  purpose.
::  
::  However, the general rule is to use map for return values and foreach
::  when you don't need the return value.  And that's what most people are
::  likely to think.  Try reading perldoc perlstyle a bit... a few tidbits:
::  
::         o   Just because you CAN do something a particular way
::             doesn't mean that you SHOULD do it that way.  Perl is
::             designed to give you several ways to do anything, so
::             consider picking the most readable one.

You can do loops in the following ways:

 1  C style for
 2  Perl style foreach
 3  for statement modifier
 4  while
 5  until
 6  bare blocks
 7  s///g
 8  m//
 9  goto
10  map
11  grep

Don't pick on map in void context. Could you please pick one, and make
a case against the other 10, and not just map?

::  The main point of map is the return value.  The main point of foreach
::  is the iteration over an array (no return value implied).
::  
::         o   Avoid using grep() (or map()) or `backticks` in a void
::             context, that is, when you just throw away their
::             return values.  Those functions all have return val-
::             ues, so use them.  Otherwise use a foreach() loop or
::             the system() function instead.
::  
::  I think this is the whole debate.  Unfortunately, there's no real
::  explicit justification here.

Which makes it just the personal preference of one man, doesn't it?

:: > "Obvious" is something subjective. *YOU* might find one way of doing
:: > something more obvious than doing it another way. But that doesn't
:: > mean it's true for everyone. Could you please explain why you find
:: > map in void context so non-obvious? Do you think map in general is
:: > non-obvious, or do you only get confused when the context is void?
:: > What about other functions in void context? Are they non-obvious too?
:: > Or is it only map that's non-obvious?
::  
::  Given that map and foreach do almost exactly the same thing with only
::  the desired contexts being different, it makes sense to me that one
::  would use the version one desires based on that context difference. 
::  Thus, when I see map in void context, the first thought in my mind is
::  "they didn't get the return from map!".

Ah, yes. Logical. There are thousands and thousands of user defined
functions whose return value isn't collected. There are many Perl
defined functions and operators whose return value isn't collected.

Noone ever makes a fuss. But if the function of which the return
value isn't collected is called "map", hundreds of Perl programmer
brains go into overload, and the programmers start running around
like chickens without their heads. "They didn't get the return from
map! They didn't get the return from map! Keep your daughters inside!
Keep your daughters inside! The end of times in coming! The antichrist
has arrived!"

I really don't get it. map in void context isn't doing anything else
than the countless of other functions in void context that are called
because of their side effects. Yet it sparks gigabytes of discussions.

::                                           Then, after scrutinising the
::  map's block (as it's usually a block not an expression), I may figure
::  out that they intended to have void (e.g., only doing it for the side
::  effect).  And then, if that's not the source of the problem, I can go
::  on.

But if the function wasn't called "map", but "zeebleflup", and it was
used in void context, would you get confused as well? What if it was
called "apply_this_function_over_the_elements_of_a_list"?

::  However, if they had used foreach to begin with, I might have been able
::  to skip over the code altogether knowing that "ignoring the return" is
::  exactly what was intended.

Again, why do you assume that if map was used in void context the
programmer was in error, and you have to confirm yourself it wasn't the
case, and you don't have this Pavlov reaction with other functions? What
makes map trigger this behaviour?

:: > Is there anyone who can explain why map in void context is confusing,
:: > but other functions aren't?
::  
::  Simply have your code say what you mean rather than trick the virtual
::  machine into doing what you want by side effect.

If I write:

    map {BLOCK} LIST;

I write *exactly* what I mean. I want to map an operation over a list.
It simple can't be named simpler.

::                                                    In general, side
::  effects make code harder to understand.

Then you shouldn't be programming in Perl. Because in Perl, you can't
do much useful without side effects.


Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


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

Date: Mon, 10 Nov 2003 12:55:29 -0500
From: Matt Oliverius <moliverius@w-link.net>
Subject: Syntax question
Message-Id: <vqvte1qsao1341@corp.supernews.com>

I'm trying to write a guestbook that appends new comments before the 
</BODY></HTML> tags.  The following Perl was used:

#!/usr/bin/perl

use CGI;

$co = new CGI;

open (BOOK, "+<book.htm")

   or die "Could not open guest book.";

seek (BOOK, -length($co->end_html), 2);

 .
 .
 .


However, I would like to put these comments into a table, so I need to back 
up before another tag, so that comments are inserted before 
</TABLE></BODY></HTML>.  How would I modify the code above to do this?








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

Date: Mon, 10 Nov 2003 21:59:08 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Syntax question
Message-Id: <boouc9$1g0a7b$1@ID-184292.news.uni-berlin.de>

Matt Oliverius wrote:
> I'm trying to write a guestbook that appends new comments before
> the </BODY></HTML> tags.  The following Perl was used:
> 
> #!/usr/bin/perl
> use CGI;
> $co = new CGI;
> open (BOOK, "+<book.htm")
>    or die "Could not open guest book.";
> seek (BOOK, -length($co->end_html), 2);
> 
> However, I would like to put these comments into a table, so I need
> to back up before another tag, so that comments are inserted before
> </TABLE></BODY></HTML>.  How would I modify the code above to do
> this?

     seek BOOK, -length($co->end_table . $co->end_html), 2;
     # print comment
     print BOOK $co->end_table, $co->end_html;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 10 Nov 2003 16:33:59 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Syntax question
Message-Id: <slrnbr04in.cmu.tadmc@magna.augustmail.com>

Matt Oliverius <moliverius@w-link.net> wrote:

> Subject: Syntax question


Your post did not contain a syntax question you know...


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


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

Date: Tue, 11 Nov 2003 00:04:17 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Tool to embed images (or other binaries)  in your Perl source.
Message-Id: <duvvqvksrbnmvc7rhs5ue8povfu4uqv18n@4ax.com>

On Fri, 07 Nov 2003 18:44:21 GMT, Marc Dashevsky <m_arc@world.std.com>
wrote:

>> Seriously, and indeed OT wrt the subject of this thread, I find
>> astonishing the difference that there's between the (sub-)cultures of
>> comp.lang.perl.misc and comp.lang.perl.tk respectively.
>
>Look, I don't read clpm, so I really don't know what goes on there,
>but I would say that the folks here generally try to help answer
>the question being asked, and don't provide unsolicited help in
>other areas, other than suggesting "use strict"!  While there may
>be some opportunities lost to help people, I think that it results
>in a newsgroup that is pretty pleasant and helpful.

And I didn't say it isn't! I apologize if I gave that impression. If
you are somehow referring to this thread itself, then people on either
group can easily ignore it and, if they like (but don't really see
why!), even killfile me.

But let me stress once more that I'm *not* saying "this is better than
this one", just reporting a difference about these two environments
that I find quite surprising, since they have both to do with the
exact same language after all...


On Sat, 08 Nov 2003 02:24:28 GMT, Ala Qumsieh <qumsieh@cim.mcgill.ca>
wrote:

>[Removed clpm from recipient list.]

Restored, I hope you won't consider this to be a move against your
will (but won't do anymore if you choose so!).

IMHO this post is (possibly) relevant to (admittedly at most a
minority of readers of) both groups.

>> Seriously, and indeed OT wrt the subject of this thread, I find
>> astonishing the difference that there's between the (sub-)cultures of
>> comp.lang.perl.misc and comp.lang.perl.tk respectively.
>
>Very very true. I used to be a regular fixture on clpm from 1998 to 2001
>until the extremely high noise-to-signal ratio drove me away (I'll admit
>though to lurking around every once in a while scavenging for gems among
>the heaps of rubbish).

This sounds surprising to me too. And it is interesting to examine
your claim in *this* context. Actually I hardly know a NG just as
informative and helpful as clpm, but then my experience is very
limited.

Also, among the other NGs I regularly follow there's sci.math: may
this be a reason why I *seem* (?) to perceive no to very limited
noise-to-signal ratio in clpm? :-)

Anyway every NG is a world of its own, with its official or
non-official rules and after being in there for a while it is easy to
understand by who is posting, subject lines and other details which
posts contribute to noise-to-signal ratio.

I choose to ignore threads that are likely to fall in the latter
category, and to follow (some of) those that don't. The practice is
not 100% sure but works most of time (wrt my personal interests).

This is not specific of clpm or clptk in any way: I *think* I read
sci.math articles efficiently too! :-)

>> Unfortunately I'm not able to report a proper review of this issue,
>> but only cite a few examples: non-strict and/or non-warnings enabled
>> scripts are much more tolerated, awkward ways to "do things" also, and
>> so on.
>
>There is a major difference between posters to both newsgroups. Most
>posters to clpm tend to be people with minimal Perl experience and are in
>the process of learning the language. Posters to clptk usually have a good

I'm not sure about this! As I said before, it is relatively easy to
predict which posts are of this kind. Generally I plainly ignore them
unless I'm sure I can help the poster (and not spend too much time
doing that).

I tend (or hope/try to) to read articles about somewhat more advanced
issues. These includes both "basic" programming techniques (and
there's *always* something to learn in this sense!!) and questions
about specific packages: more on this later!

>grasp on Perl, but are learning Tk. Not everyone is interested in learning
>the "proper" techniques/styles/conventions/etc. But everyone wants to see
>their app working. And that's perfectly fine. Larry Wall himself said that

OK, I agree...

 ...but! Take *for example* articles on a specific package, as hinted
above: maybe the user knows it is what he needs and he has a rough
knowledge of perl basic syntax. But often it happens that his actual
problem has to do with something other than that specific package.

So "unsolicited help" is most often (IMHO!) effective help, and it is
only a problem of each particular user wether to consider it such or
not!

>it's fine for people to program in "baby Perl" (can't remember the quote
>exactly, but lurk long enough on clpm and you'll see it in someone's sig).

No, it's not in anyone's .sig currently, but IIRC it's somewhere in
the docs or some site of easy access on the web. I know what you're
referring to!

>People come to clptk to learn about Tk. And what they find is Tk.
>
>> Please, note that I'm *not* saying that "pTk programmers write crappy
>> code", only that in CLPT while the attention is focused on GUI's logic
>> and features much less care *seems* to be dedicated to the
>> ("remaining") perl code itself.
>
>That is not true most of the time. There are some very good Perl
>coders on clptk, and there are many cases here where better
>approaches were given based on the quality of the code. But it's more

You're right, even if my follow/ignore ratio is even lower here than
elsewhere, I know I happened to see such a beast. But it's not rare to
have to do with posters who basically are fiddling with pTk w/o being
confident with basilar concepts of Perl.

I remember a case along the lines of a poster being suggested to
"store buttons" as key/value pairs in a hash whereas *that* poster
didn't basically know what a hash was (but was using hashrefs
routinely as args to pTk methods). And my claim is that similar
situations are not that rare...

>important to teach Tk here. People can learn Perl elsewhere.

Perfectly fine!

>> But this involves also posting policies: a post like this one (the one
>> I'm following-up to) containing no proper quotations and/or references
>> usually generates a chorus of complaints in CLPM.
>
>And how is this a good thing? Ok .. proper posting techniques do help in
>reading the posts, but not following them doesn't warrant the childish

Well, posting guidelines are a tool to help knowledgeable users to
help us. Indeed the fact they are more strict on clpm than on clptk
has to do with the traffic volume in the former group over that in the
latter.

>responses that clpm regulars reply with. If you don't understand a post,
>either ask for clarification, or move on. Arguments like "don't top-post",
>"don't quote the whole article", "leave at least one empty line between

IMHO these are not childish responses. A correct posting policy helps
both the OP and those who decide to follow-up. Generally one is gently
advised not to do so, the first time (depending on the content of his
post); but if he insists, then they *correctly* consider him not to be
respectful wrt those who take care of providing a helpful hand for
him.

>quoted text and your reply", "always use strict", "always check results of
>your opens", etc, are becoming more of a nuisance. And the strange thing

This is a completely different issue! I do not have any statistics
available, but I think that it actually turns out that in the vast
majority of cases the problem was not using strict or checking the
results of opens. Especially when (e.g.) at the very least a "or die
$!" suffices...

The whole point is that there is probably no point in "making the app
work" if e.g. open()s are not checked for success, because in that
case the app is not likely to work correctly in any case!

>is that they are contagious. Lurk on clpm long enough, and you'll be
>saying the same things. That's when I decided to stop.

I'm a clpm *regular*, and a clptk (mostly) lurking regular. I don't
think *that* is a thing that will ever drive me to eventually decide
to stop.

>unfortunately, clpm has attracted many a troll, and silly, off-topic and
>completely condescending posts have pushed me away.

Actually silly/OT posts can be isolated quite easily. But that is only
my experience! OTOH there's a resident troll that IMHO is not even a
"real" troll and can be ignored quite easily and pailessly as well.

>I'm getting old. I'm sticking to the quiet life of clptk :)

Oh, hope not to have upset it! :-)

Seriously, this is something I've wanted to talk about for a long
time. I hope not to have bothered anyone by taking the floor and
finally doing that.


Thanks,
Michele
-- 
$\=q.,.,$_=q.print'  ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;


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

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.  

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


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