[23866] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6069 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 3 00:05:55 2004

Date: Mon, 2 Feb 2004 21:05:04 -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, 2 Feb 2004     Volume: 10 Number: 6069

Today's topics:
    Re: 'Eval'uating a variable <xxala_qumsiehxx@xxyahooxx.com>
    Re: 'Eval'uating a variable <dmcbride@naboo.to.org.no.spam.for.me>
    Re: Checking to see if a paticular file exists <tadmc@augustmail.com>
    Re: Checking to see if a paticular file exists <emschwar@pobox.com>
    Re: Help with sleep and file open <tadmc@augustmail.com>
    Re: How to know the input line number when using parse_ (Himanshu Garg)
    Re: One liner: "&&" all elements of array <tadmc@augustmail.com>
    Re: One liner: "&&" all elements of array <irving_kimura@lycos.com>
    Re: open a ascii file and rotate the content 90 deg... (Rich)
    Re: Perl For Amateur Computer Programmers <bigiain@mightymedia.com.au>
        V 5.8 specific problem? (Marty Landman)
    Re: V 5.8 specific problem? <emschwar@pobox.com>
    Re: When to "use strict" when teaching? <tadmc@augustmail.com>
    Re: When to "use strict" when teaching? <tadmc@augustmail.com>
    Re: When to "use strict" when teaching? <matthew.garrish@sympatico.ca>
    Re: When to "use strict" when teaching? <drumspoorly@reachone.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 02 Feb 2004 23:49:22 GMT
From: "Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: 'Eval'uating a variable
Message-Id: <6mBTb.19189$HE4.14005@newssvr27.news.prodigy.com>

"Prabh" <Prab_kar@hotmail.com> wrote in message
news:e7774537.0402021350.3631a43a@posting.google.com...
>
> logfile = ${USER_HOME}/logfiles/log.txt
>
> My program traverses through this properties file, finds a match for
> logfile setting, gets the value of this setting and needs to expand
> the USER_HOME variable as follows,

The special %ENV hash will contain all your environment variables. Check it
out in perlvar.

>
============================================================================
==
> if ( $line =~ /^logfile/ )
> {
>     my $log_to_file = (split(/(\s)*\=(\s)*/, $line))[1] ;
>
>     # BTW, is 'split' the best way to obtain the value.
>     # I tried using the regular expressions, but cant find a way to do
>     # w/o an 'if conditional.'
> }
>
> $log_to_file_after_eval = eval($log_to_file) ;

This code is broken since you declar $log_to_file as a lexical variable
within the if() block, but attempt to use it outside the block. Also, you
seem to miss the point of eval(). It treats its first argument as either a
Perl expression or a block of Perl code and try to run it and return its
return value. In your case, it will treat whatever is inside $log_to_file
(which should be '${USER_HOME}') as a Perl snippet, which will return undef
since $USER_HOME is not defined (from what we see).

As for your code, I'd re-write it this way (untested):

  my $log_to_file;
  if ($line =~ /^logfile\s+=\s+(\S+)/) {
    $log_to_file = $1;
    $log_to_file =~ s/\{(\S+?)\}/$ENV{$1}/g;
  }

This is ofcourse a rather simplistic approach, but you don't give us too
much data to work with :)

>
============================================================================
==
>
> The eval returns null. So, I'm doing it the hacky way, extracting the
> environment variable part of it ( the text between "${" and "}" ) and
> splitting it from the rest of the setting value.
>
>
============================================================================
==
> if ( $log_to_file =~ m/^\s*\$\{(.*)\}(.)*/ )
> {
>     $user_home_path = $1 ;
>     $rest_of_path   = $2 ;
>     # Put the "${ENV" in front of it, to supply it to eval.
>     $user_home_path = '$ENV{'."$user_home_path"."}' ;
> }
>
> $after_eval = eval($user_home_path} ;
> $user_home_after_eval = "$after_eval"."$rest_of_path" ;
> print "This is path after eval:  $usr_home_after_eval\n";

Why not simply:
  $after_eval = $ENV{$user_home_path};

??

--Ala




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

Date: Tue, 03 Feb 2004 00:06:41 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: 'Eval'uating a variable
Message-Id: <lCBTb.386232$X%5.342636@pd7tw2no>

Prabh wrote:

> Hello all,
> I've a question about the using the eval function at runtime.
> I can evaluate a varible, $foo, as
> 
> my $bar = eval($foo) ;
> 
> But when theres some extra string at the end of $foo, the eval fails
> to return any value,
> 
> my $bar = eval($foo/moretext) ;

From what I can tell, this is:

* Take $foo.
* Divide it by the return from moretext().
* evaluate the number so returned.

Perhaps if you used strict and warnings, something useful would have
popped up....?

> The value of $foo is to be interpolated at the run-time.
> If at runtime it interpolates as, "/home/123user", is it possible for
> me to eval my $bar as "/home/123user/moretext".

As posted by Gunnar: C<EXPR1 . EXPR2> is what you're looking for. 
Specifically, eval($foo) . "/moretext".  Personally, I'd do:
File::Spec->catfile(eval($foo), 'moretext');
But that's because I like my stuff to look cross-platform, even if the
concept is uni-platform.  For example, one script I have wraps around
rpm - that's definitely Linux-only (well, and AIX, but that's still
unix).  But I still use File::Spec to show that I'm working with file
specifications (full pathnames), not just arbitrary strings.

> Reason I ask,
> I've a file full of property settings, one of which sets the location
> of logfile, as follows,
> 
> logfile = ${USER_HOME}/logfiles/log.txt

There are sooooo many ways to do this that I'll forget some.

1. Heavy-handed, slow, and deadly accurate:

Filter the file with s/\s*=\s*/=/ into another file.  Then use
C<open(CFG,". $tmpfile; set|")> (with appropriate error handling).  Each
line from this will be already evaluated properly.  You'll end up with
too much stuff, though, things like PATH, LIB_PATH, etc, but the config
parms you want will be in there, too.  But you don't need to worry
about things like differentiating between $USER_HOME and ${USER_HOME}
and ${USER_HOME?} and ${USER_HOME#*/} and ...

Of course, this is extremely non-portable.  Perhaps that's not a
concern for you in this case.

2. Portable, perhaps fast (no subprocesses):

Use the following re (or something similar - this is untested) to read
it in:

open(CFG, "...") or die "can't open cfg file";
while (<CFG>)
{
   s/\$(?:{(\w+)}|(\w+))/$ENV{$1||$2}/eg;
   if (/^\s*(\w+)\s*=\s*(\w+)/)
   {
      $cfg{lc $1} = $2;
   }
}
close CFG;

# now use $cfg{logfile} as your log_to_file variable.


Another small variation may be to allow the cfg file to refer to
earlier variables as if they override the environment:

s/\$(?:{(\w+)}|(\w+))/$cfg{$1||$2}||$ENV{$1||$2}/eg;

Now you can set USER_HOME at the top of the config file, and all
further occurances of $USER_HOME will use that one.

All without any use of eval.  :-)

> The eval returns null. So, I'm doing it the hacky way, extracting the
> environment variable part of it ( the text between "${" and "}" ) and
> splitting it from the rest of the setting value.
> 
> 
==============================================================================
> if ( $log_to_file =~ m/^\s*\$\{(.*)\}(.)*/ )
> {
>     $user_home_path = $1 ;
>     $rest_of_path   = $2 ;
>     # Put the "${ENV" in front of it, to supply it to eval.
>     $user_home_path = '$ENV{'."$user_home_path"."}' ;

Tricky stuff.  Why bother with eval?  Just use

     $user_home_path = $ENV{$user_home_path} ;

Note that you're assuming that ${...} appears at the front of your
string, and only once.  What if the user does:

logfile = ${USER_HOME}/${LOGDIR}/logfile.txt

?  How much of this stuff do you really want to support?  :-)

> }
> $after_eval = eval($user_home_path} ;
> $user_home_after_eval = "$after_eval"."$rest_of_path" ;
> print "This is path after eval:  $usr_home_after_eval\n";
> 
> 
==============================================================================
> 
> I'm wondering if theres a more elegant solution for this.
> I've a feeling this might get more and more complicated, like some
> users may not wrap the variable with {}.

You can define your own config file language.  If you want to force
users to use {}, do so.  :-)

if (/\$[^{]/ or /\$[^}]*$/)
{
  die "$ without {}!"
}


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

Date: Mon, 2 Feb 2004 17:47:12 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Checking to see if a paticular file exists
Message-Id: <slrnc1toc0.e65.tadmc@magna.augustmail.com>

vijay <vijaysenthilv@yahoo.com> wrote:

>   I'm trying to check to see if a paticular file exist on the machine,


Show us your code that is trying to check to see if a paticular file 
exist on the machine, and we will help you fix it.


> If i run the script from the command prompt they
> seem to run fine, but when i try to open the script on a browser, it
                                                           ^^^^^^^
> is not able to even open the directory, i get a Invalid Argument

   perldoc -q browser

       My CGI script runs from the command line but not the browser.  (500
       Server Error)


> Any help is greatly appreciated


Any code is greatly appreciated.


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


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

Date: Mon, 02 Feb 2004 14:30:30 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Checking to see if a paticular file exists
Message-Id: <eto65epf9u1.fsf@fc.hp.com>

vijaysenthilv@yahoo.com (vijay) writes:
>   I'm trying to check to see if a paticular file exist on the machine,
> i'm unable to check for files insides directories which have space in
> between their names, If i run the script from the command prompt they
> seem to run fine, but when i try to open the script on a browser, it
> is not able to even open the directory, i get a Invalid Argument
> Error

perldoc -q 500

<wavy lines>
use PSI::ESP;

print <<EOGUESS;

I bet you're not using CGI.pm, and you're not decoding URI-encoded
entities properly.  After you've followed all the directions in the
FAQ I just referred you to, try creating a small CGI program, using
CGI.pm, that just prints out "It exists", or "It doesn't exist" when
you pass a filename as a parameter.  It shouldn't take more than 10
lines.  Doing this will probably help you debug your problem.

EOGUESS
__END__
</wavy lines>


-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Mon, 2 Feb 2004 15:58:37 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help with sleep and file open
Message-Id: <slrnc1ti0d.e65.tadmc@magna.augustmail.com>

Bob <horseyride@hotmail.com> wrote:

> I would have expected the code below to sleep for 10 seconds, 


If you call sleep() with an argument of 1, it will not sleep for 10 seconds.


> up to 15
> tries, in attempting to open the data file before continuing. Instead
> it *always* seems sleep 15 tries before continuing. 


It works for me...


> Can someone please
> tell what what I did wrong?


Didn't post a short and complete program that we can run that
illustrates your problem.

Didn't indent your code.

Called die() when you didn't want to die().

Used a goto.

Didn't report the value of $!.



Maybe this is what you wanted?

---------------------------------------
my $SAV = my_open($filename) or die "could not open '$filename'  $!";
# ...
sub my_open {
    my($fname) = @_;
    foreach my $trycount ( 1 .. 15 ) {
        if ( open my $fh, ">>$fname" ) {
           return $fh;
        }
        sleep (1);
        print "Slept: $trycount\n";
    }
    return undef;
}
---------------------------------------


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


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

Date: 2 Feb 2004 19:08:34 -0800
From: himanshu@gdit.iiit.net (Himanshu Garg)
Subject: Re: How to know the input line number when using parse_file of HTML::Parser
Message-Id: <a46e54c7.0402021908.27868a59@posting.google.com>

ko <kuujinbo@hotmail.com> wrote in message news:<bvlg0k$bsh$1@pin3.tky.plala.or.jp>...
> Himanshu Garg wrote:
> > Hello,
> >     
> >     I am using HTML::Parser and want to know the line number where a
> > particular event occurs.
> 
> [snip code/warning message]
> 
> > Could you suggest the right ways of getting the line number, please.
> > The input I am parsing is erroneous and I want to know the location of
> > errors. Hence the above code.
> > 
> > Thank You
> > Himanshu.
> 
> Start off by re-reading the documentation. The part you're looking for 
> is  in the 'Argspec' section, specifically the 'line' argspec 
> identifier. Use something like this:
> 
> #!/usr/bin/perl -w
> use strict;
> use HTML::Parser;
> 
> undef $/;
> my $html = <DATA>;
> my $p = HTML::Parser->new( api_version => 3,
>    start_h => [sub { print shift, "\n"; }, 'line'],
> );
> $p->report_tags('s');
> $p->parse($html);
> $p->eof;
> 
> __DATA__
> <html>
> <body>
> <s>paragraph</s>
> <pre>
> 
> </pre>
> <s>paragraph</s>
> <body>
> </html>
> 
> There are a lot of good examples here:
> 
> http://search.cpan.org/src/GAAS/HTML-Parser-3.34/eg/
> 
> HTH - keith

    Thanks a lot.

Thank You
++imanshu.


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

Date: Mon, 2 Feb 2004 17:43:32 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: One liner: "&&" all elements of array
Message-Id: <slrnc1to54.e65.tadmc@magna.augustmail.com>

Irving Kimura <irving_kimura@lycos.com> wrote:

> I'm looking for the most compact way in Perl to 


That is called "Perl golf".

Mentioning "golf" in your subject would help draw in
the character-frugal type of Perl folks.


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


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

Date: Mon, 2 Feb 2004 22:30:10 +0000 (UTC)
From: Irving Kimura <irving_kimura@lycos.com>
Subject: Re: One liner: "&&" all elements of array
Message-Id: <bvmj1i$ss3$1@reader2.panix.com>

In <bvma8a$jni$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>The 'or' can be shortened by one character:

>+grep $_, @array;

I thought of that, but when I try

  perl -le 'print +grep $_, (1, 1)'

I get 11 as the printout, surprisingly enough...

After my original post, I realized that the grep-based solutions
have an additional virtue besides brevity.  They do the right thing
if one wants to generalize the definition of the && and || operators
to the "pathological" cases of a single operand, and no operands:

  sub And { !grep !$_, @_ }
  sub Or  { !!grep $_, @_ }
  And(1)  => 1
  And(0)  => 
  And()   => 1
  Or(1)   => 1
  Or(0)   => 
  Or()    => 

(There are analogous generalizations for the intersection and union
operators in set theory.)

So this way of implementing ands and ors is not only succinct but
also "mathematically correct" in some sense.  Even Python-heads
have got to like that!

Irv



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

Date: 2 Feb 2004 15:22:50 -0800
From: richman_b@hotmail.com (Rich)
Subject: Re: open a ascii file and rotate the content 90 deg...
Message-Id: <117a85b8.0402021522.50c2834d@posting.google.com>

Brian McCauley <nobull@mail.com> wrote in message news:<u9y8rlehy7.fsf@wcl-l.bham.ac.uk>...
> lyoute <lyoute@softhome.net> writes:
> 
> > i got a set of files all looks like: (with fixed dimension 8x8)
> > .X..XO..
> > X...XO..
> > OXX.XO..
> > OOOXXO..
> > ...OO.O.
> > ..O.....
> > ........
> > ........
> > 
> > how can i produce output with 90 deg rotated:
> > .XOO....
> > X.XO....
> > ..XO.O..
> > ...XO...
> > XXXXO...
> > OOOO....
> > ....O...
> > ........
> 
> That is not rotation, that is reflection.

Yes - all that has been done are interchange the references to rows
and columns. Like a matrix transpose.


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

Date: Tue, 03 Feb 2004 15:43:47 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <bigiain-39F8C2.15434703022004@news.fu-berlin.de>

In article <qkOSb.4022$jH6.3447@newsread1.news.atl.earthlink.net>,
 "edgrsprj" <edgrsprj@ix.netcom.com> wrote:

> As I stated in some recent posts, I have been looking for a programming
> language which scientists and other people around the world who are not
> professional computer programmers could use with the same ease as Basic.

<snip>

> 
> If you are trying to make the transition from some language such as Basic to
> Perl it can be difficult because of the very large number of commands etc.
> which are available in Perl, because of their many options, and because of
> Perl's structure which I myself do not yet fully understand.  So what I have
> been doing while I have been learning how to use it during the past few
> weeks is prepare a Web page which briefly outlines some of its basic
> commands etc.  People who can already write simple programs in other
> languages can use those commands to almost immediately begin creating and
> running simple Perl programs.

Keep in mind the joke-with-a-seed-of-truth:

"Perl makes a lousy first programming language, thats because its 
designed to be the *last* programming language you ever need to learn."

:-)

The seed of truth is both about its pretty universal usefulness 
(realtime 3d rendering and similar problems excepted), but also, as you 
mention, it has documentation containing things like this:

>perldoc -f sprintf

       sprintf FORMAT, LIST
               Returns a string formatted by the usual `printf'
               conventions of the C library function `sprintf'.
               See sprintf(3) or printf(3) on your system for an
               explanation of the general principles.


People with a few other languages under their belts wont be too fazed by 
that, and will work out they need to try the system man pages and get 
something like:

>man 3 sprintf

PRINTF(3)           Linux Programmer's Manual           PRINTF(3)

NAME
       printf,  fprintf,  sprintf,  snprintf,  vprintf, vfprintf,
       vsprintf, vsnprintf - formatted output conversion

SYNOPSIS
       #include <stdio.h>

       int printf(const char *format, ...);
       int fprintf(FILE *stream, const char *format, ...);
       int sprintf(char *str, const char *format, ...);
       int snprintf(char *str, size_t size, const  char  *format,
       ...);

Which is fine if you once knew enough c to be able to work out what you 
get there, but like you've identified, its not in the useful for "people 
around the world who are not professional computer programmers could use 
with the same ease as Basic" category...

(note, the perldoc -f sprintf doco actually does go on a lot more than 
just the bit I quoted up there, but I think my arguement holds - in that 
I suspect a complete programming beginner is going to be completely 
mystified by everything it provides, its clearly written for a 
non-newbie audience. Perhaps intentionally - maybe the doco 
writers/maintainers aren't intending to write beginners programming 
doco, but _programmers_ programming doco...)

big

-- 
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto


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

Date: 2 Feb 2004 17:23:55 -0800
From: marty@face2interface.com (Marty Landman)
Subject: V 5.8 specific problem?
Message-Id: <b9e0e6f4.0402021723.58cd53a5@posting.google.com>

I'm running the same software on three different servers. All 3 are
FBSD running Perl v5.005_03. Recently I ported to a RH9 Linux server
which runs Perl v5.8.0. One part of the software is causing the
following in my Apache error log:

"Attempt to bless into a reference at..."

the referenced line contains

	my $quiz = bless { _q => $_q, _a => $_a },$Quiz;

I've compared the copy on this machine and one of the 3 where it
works. Also if I just comment out the call that caused this package to
be used everything works just fine.

While it may obviously be something just not thought of by me (imagine
that) given the difference in Perl versions I'm wondering if this is a
feature or bug of the 5.8 release. Since the Linux box belongs to me
and is a sandbox I could just rpm -e Perl 5.8 and install 5.0x from a
cpan distro. But then again maybe it's something I need to pay better
attention to.

Any help, ideas etc.. most appreciated.

Thanks in advance,


Marty Landman   Face 2 Interface Inc 845-679-9387
This Month's New Quiz --- Past Superbowl Winners
Make a Website: http://face2interface.com/Home/Demo.shtml


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

Date: Mon, 02 Feb 2004 18:46:34 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: V 5.8 specific problem?
Message-Id: <etoznc1c4ud.fsf@fc.hp.com>

marty@face2interface.com (Marty Landman) writes:
> I'm running the same software on three different servers. All 3 are
> FBSD running Perl v5.005_03.

This is truly ancient (nearly 5 years old), and has all sorts of nasty
bugs (security-related and otherwise).  It's a good thing you're
upgrading.

> Recently I ported to a RH9 Linux server which runs Perl v5.8.0. One
> part of the software is causing the following in my Apache error
> log:
>
> "Attempt to bless into a reference at..."
>
> the referenced line contains
>
> 	my $quiz = bless { _q => $_q, _a => $_a },$Quiz;

Check the documentation on Perl diagnostics with 'perldoc perldiag'
and read the entry your message refers to.  If you don't understand
something about that answer, please let us know what it is, and we'll
try to help.

$Quiz (as a personal aside, I hate it when a line of code includes two
variables named identically except for case) is probably not what you
think it is.  You probably should print it out and see what you're
trying to bless that anon hashref into.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Mon, 2 Feb 2004 17:24:45 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: When to "use strict" when teaching?
Message-Id: <slrnc1tn1t.e65.tadmc@magna.augustmail.com>

Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
> I'm thinking about putting together a a series of evening classes at 
> work for a group of people who are interested in learning Perl.  I'm 
> just thinking about how to split things up and the best approaches to 
> take.  A couple of quetions presented themselves and I though I'd 
> solicit opinions from others who have done this sort of thing before.


There is a mailing list where Perl trainers hang out to discuss
just such things:

   A discussion list for people who teach Perl.
   http://lists.perl.org/showlist.cgi?name=perl-trainers

[ mention this thread if you also ask there. ]


> 1) When do you think it's best to introduce strictures into the programs 
> people write.  


As soon as you've covered scoping.


> Many moons back I learnt Perl using Learning Perl, which 
> I found to be excellent, but looking back I see that it doesn't 
> introduce the concept of strictures into any of the basic exercises.  


It does in the 3rd edition, right after it's covered scoping.  :-)


[ not in the 1st edition: use strict was introduced in Perl 5,
                          after the Llama 1e was published.
  not in the 2nd edition: too many folks were still using Perl 4
                          and it would have confused them when it
                          didn't work.

  But you can't take my word for it, I am very biased.  :-)
]


> I 
> remember that adapting my programming to using strictures was one of the 
> harder things I had to get my head around, 


Strictures is easy.

Scoping is hard.

Are you sure you've fingered the right culprit?


This will be helpful when you teach scoping in Perl:

   "Coping with Scoping":

      http://perl.plover.com/FAQs/Namespaces.html


> and I wonder if it would have 
> been easier to have started off by writing all programs under warnings 
> (+diagnostics) and strict?


Now you've changed it into a 2-pronged question, and I (at least)
would give different answers for the 2 parts.

I would agree to introduce warnings right near the start, after
a "hello world" program or two.

Strictures need to wait until they've seen scoping.


> 2) How much Perl do you reckon people can comfortably take in one 
> sitting?  I'm in the nice position of being able to spread the training 
> in short sesssions over several weeks so that people don't get 
> overloaded 


That is indeed a very nice position.


> (most will never have done any programming before at all). 


That would, in my estimation, double the time needed for getting
to where they can write Perl programs that get their jobs done.


> Most technical courses I've seen suffer from throwing too much 
> information at people which results in them not retaining much of it.  


That is very true.


> I 
> was thinking of 1.5 hours at a stretch and maybe 10 sessions in total 
> (with exercises in between), to give them a good introduction to the 
> language.


15 hours seems pretty short.

I get 28 contact hours in a typical Stonehenge class, with an
"already programmed in some other language" prerequisite, and
there are _still_ things I want to say but don't have time to say.

(of course, it may be that I'm just a bigmouth...)


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


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

Date: Mon, 2 Feb 2004 17:36:46 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: When to "use strict" when teaching?
Message-Id: <slrnc1tnoe.e65.tadmc@magna.augustmail.com>

Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:
>>>>>> "JL" == Juha Laiho <Juha.Laiho@iki.fi> writes:
> 
>    JL> I think I'd try to get the students use warnings and
>    JL> strictures from the start. But this depends on how much things
>    JL> your students allow as "just do it this way", without
>    JL> questioning and/or requiring in-depth explanation.
> 
> Students tend not to like being told "Just do it this way, because I
> said so" -- but they're often willing to put up with "Do it this way
> for now; there are times you will want to do something differently,
> but I can't explain everything at once, and this is something I'll
> explain later."  Especially if you actually *do* explain bits of it
> later on.


I would agree for "use strict".

For "use warnings" an in-depth explanation shouldn't be needed,
a "what's in it for me?" explanation ought to win them over, so
you can introduce warnings straightaway.

I tell them:

   I've programmed in Perl every day for eight years, and _I_
   want the help that warnings offers me.

   You, as beginners, should want it even more than I do, as
   you are even more likely to make the "common mistakes" that
   warnings are designed to find.

Then later in the training there are 4 or 5 places where warnings
would have caught the problem being discussed, and I give them:

   Without warnings you would have just gotten "strange output",
   scratched your head, and launched a debugging session that
   could last minutes or hours.

   With warnings the problem would have been found in a few milliseconds.

   Warnings are optional, you get to choose which way you would 
   prefer to operate.

:-)


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


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

Date: Mon, 2 Feb 2004 21:56:54 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: When to "use strict" when teaching?
Message-Id: <P5ETb.6759$9U5.424974@news20.bellglobal.com>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnc1tn1t.e65.tadmc@magna.augustmail.com...
> Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
> > I
> > was thinking of 1.5 hours at a stretch and maybe 10 sessions in total
> > (with exercises in between), to give them a good introduction to the
> > language.
>
>
> 15 hours seems pretty short.
>
> I get 28 contact hours in a typical Stonehenge class, with an
> "already programmed in some other language" prerequisite, and
> there are _still_ things I want to say but don't have time to say.
>

15 hours should be ample time to begin to get a grasp on regular
expressions, and regexes are so key to Perl (IMHO) it seems almost pointless
to not lay that foundation first. I suppose you have to bear in mind that he
is only proposing an informational session. I suspect that you would be
teaching programmers who need a crash course in the language, whereas his
audience might be happy if they can open files and modify the contents at
the end.

To the OP, I would try and establish what it is your users would most
benefit from learning (be it regexes, Perl for cgi, or whatever) and just
focus on that particular aspect. Once they're up and running they'll
hopefully do the research necessary to build on the foundation.

Matt




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

Date: Mon, 02 Feb 2004 19:49:35 -0800
From: Steve May <drumspoorly@reachone.net>
Subject: Re: When to "use strict" when teaching?
Message-Id: <101u6a83e67kg67@corp.supernews.com>

Tad McClellan wrote:
> 
> 
> Now you've changed it into a 2-pronged question, and I (at least)
> would give different answers for the 2 parts.
> 
> I would agree to introduce warnings right near the start, after
> a "hello world" program or two.
> 
> Strictures need to wait until they've seen scoping.
> 
> 
> 

Hmmm.... Not a Perl trainer, though I am certified (-able?)
in a few other subjects.

But, I'd think something along the lines of:


Excercise #1

#! /usr/bin/perl

print "Hello World!\n";

exit;


Excercise #2

#! /usr/bin/perl

my $string = 'Hello World!';

print "$string\n";

exit;


Excercise #3

#! /usr/bin/perl

my $string = 'Hello World!';

print "$striing\n";

exit;


Excercise #4

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

my $string = 'Hello World!';

print "$striing\n";

exit;


#4 lets students see for themselves the advantage
of Perl doing the drudge work.....

Just a thought....


s.



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

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


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