[19324] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1519 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 14 11:05:33 2001

Date: Tue, 14 Aug 2001 08:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997801511-v10-i1519@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 14 Aug 2001     Volume: 10 Number: 1519

Today's topics:
        2 dimensional array suntax help, please (Stan Brown)
    Re: 2 dimensional array suntax help, please <samneric@DE-SPAMtigerriver.com>
    Re: Comma's at end of list can break program?? <mjcarman@home.com>
    Re: Comma's at end of list can break program?? (Anno Siegel)
    Re: dates <eric@mizuhocap.com>
    Re: Flock: Just to be sure ! (Tad McClellan)
        Format error?? <miscellaneousemail@yahoo.com>
    Re: get rid of these leading zeros in Perl <josef.moellers@fujitsu-siemens.com>
    Re: get rid of these leading zeros in Perl (Anno Siegel)
    Re: get rid of these leading zeros in Perl (Tad McClellan)
        grep 5th word in a text-file <trinks@prolink.de>
    Re: grep 5th word in a text-file (Rafael Garcia-Suarez)
    Re: How do I assing an entire array? (Stan Brown)
    Re: How do I assing an entire array? <bart.lateur@skynet.be>
        modules and variables <cyberjeff@sprintmail.com>
    Re: Passing parameters to subroutines (John J. Trammell)
    Re: Passing parameters to subroutines <bart.lateur@skynet.be>
    Re: perldoc is like Greek to a beginner?? (Yves Orton)
    Re: perldoc is like Greek to a beginner?? (Yves Orton)
    Re: Possible perl/DOS bug? <bcaligari@fireforged.com>
        printing from windows (gdi32) (Mike Solomon)
    Re: printing from windows (gdi32) (Eric Bohlman)
    Re: regex question... <strawSPAM_BEGONEman@plexi.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 14 Aug 2001 09:15:39 -0400
From: stanb@panix.com (Stan Brown)
Subject: 2 dimensional array suntax help, please
Message-Id: <9lb89r$g8d$1@panix2.panix.com>

Just as I thought I was getting a handle on this, I have managed to confuse
myself again :-(

I have a subroutine I call that creates and array of refeences to arrays.
The relevant bits look like this:

my @rval = undef ;

$rc = $sths->execute or die $DBI::errstr;
my $row = 0;
my $col = 0;
while ( @extracted_data = $sths->fetchrow_array ) {
	for ($col = 0; $col < $col_qty; $col++) {
	$rval[$col][$row] = $extracted_data[$col];
	print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
	}
	$row++;
}

return @rval;

All of this _seems_ br working corectly. The trouble arises in using it.
Like this:

my $vals = get_foreign_key_values(
		$$hash_pointer{$col}{'SRC_TABLE'},
		$$hash_pointer{$col}{'SRC_COLS'});
$entry->insert(0,$$vals[0]);


What have I got wrong here?




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

Date: Tue, 14 Aug 2001 10:05:57 -0400
From: Samneric <samneric@DE-SPAMtigerriver.com>
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <MPG.15e2fa36d1566a7989682@news.usit.net>

In article <9lb89r$g8d$1@panix2.panix.com>, stanb@panix.com says...
> I have a subroutine I call that creates and array of refeences to arrays.

No, it doesn't. There are no arrayrefs in @rval.

> my @rval = undef ;
> $rc = $sths->execute or die $DBI::errstr;
> my $row = 0;
> my $col = 0;

$row needs to be initialised here, but $col gets initialised in "for" loop.

> while ( @extracted_data = $sths->fetchrow_array ) {

You're retrieving the data for the row here. It consists of column data. Yet 
your code refers to [col][row] rather than [row][col] - (semantic liberties 
taken by me). That's backwards. You want to create an array of rows consisting 
of arrays of columns - not an array of columns conisting of arrays of rows.

$rval[$row] = []; # first, create empty array for this row's columns

> 	for ($col = 0; $col < $col_qty; $col++) {

Where do you set $col_qty?? Why not use "$col < @extracted_data"??

> 	$rval[$col][$row] = $extracted_data[$col];

$rval[$row]->[$col] = $extracted_data[$col];

> 	print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);

Here you use [row][col], see?

> 	}
> 	$row++;
> }
> return @rval;
> All of this _seems_ br working corectly. The trouble arises in using it.
> Like this:
> 
> my $vals = get_foreign_key_values(
> 		$$hash_pointer{$col}{'SRC_TABLE'},
> 		$$hash_pointer{$col}{'SRC_COLS'});
> $entry->insert(0,$$vals[0]);

I have no idea where you populate $hash_pointer, or what it contains. But you 
can access the values that you returned in @rval via:

$column_value = $rval[$row]->[$col];

Where:
$num_rows = @rval;
$num_cols_in_row = @{$rval[$row]};




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

Date: Tue, 14 Aug 2001 08:15:43 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Comma's at end of list can break program??
Message-Id: <3B79247F.8965F333@home.com>

Logan Shaw wrote:
> 
> [C]ommas after the last item in lists in Perl are a matter of the
> maintainer who forgets Perl syntax either (a) not noticing that
> anything happened (if I put them), or (b) getting this error message
> (if I don't put them):
> 
>      String found where operator expected at $FILENAME line $LINE,
>      near "$LIST_ITEM"
>              (Missing semicolon on previous line?)
> 
> where $FILENAME, $LINE, and $LIST_ITEM are values supplied by the
> interpreter.
> 
> IMHO, if they can't figure that message out in 9 seconds, they need to
> be in another profession.

True, but (IMHO) that misses the point. Even experienced programmers
will occasionally miss a comma. If I can save 9 seconds of nuisance
debugging by habitually putting in that "superfluous comma" it's worth
it.

This feature is one of the little things that I really like about Perl.
Perl does an amazing job of letting me focus on the problem, not the
implementation. I won't argue that allowing a trailing comma is as
useful as automatic memory management, but it is one less thing that I
have to fuss with, and that makes me happy.

Sometimes I put the trailing comma there just because I can. It's a
small form of retaliation against those languages which are paranoid
about such things. :)

-mjc


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

Date: 14 Aug 2001 14:33:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Comma's at end of list can break program??
Message-Id: <9lbcsj$etu$2@mamenchi.zrz.TU-Berlin.DE>

According to Michael Carman  <mjcarman@home.com>:

[...]

> Sometimes I put the trailing comma there just because I can. It's a
> small form of retaliation against those languages which are paranoid
> about such things. :)

Yay!  The best reason I've heard so far :)

Otherwise, I wouldn't make a religion out of the final comma.  As many
optional features it can be used as a hint for posterity:  If it's there,
a maintainer may conclude she is supposed to make changes there, which
can be comforting.  If it isn't, she'll make her changes anyhow.

Anno


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

Date: Tue, 14 Aug 2001 10:27:38 -0400
From: Eric <eric@mizuhocap.com>
Subject: Re: dates
Message-Id: <3B79355A.160A894D@mizuhocap.com>

Just awsome.
Beauty in simplicity,
Clean and economical.
Nice stuff.

This is why it's a good idea to
browse this news group.

Thank you,
Eric


"John W. Krahn" wrote:

> Dave McLean wrote:
> >
> > Hi, I'm trying to, given a date, determine the date of the first and last
> > days of the week that the given date falls in. I've written this and it
> > works fine for the end of the week but not for the the begining:
> >
> > given:
> > $date = "1999-08-13";
> >
> > if( strftime( "%A", "$date" ) eq 'Sunday' ){
> > $week_start = $date;
> > }else{
> > $week_start = strftime( "%Y-%m-%d", localtime( parsedate( "last sunday", NOW
> > => parsedate( $date ) ) ) );
> > }
> >
> > if( strftime( "%A", "$date" ) eq 'Saturday' ){
> > $week_start = $date;
> > }else{
> > $week_start = strftime( "%Y-%m-%d", localtime( parsedate( "next saturday",
> > NOW => parsedate( $date ) ) ) );
> > }
> >
> > for some reason, every date yields "Sunday" for week start
> >
> > any suggestions, thoughts, comments?
>
> #!/usr/bin/perl -w
> use strict;
> use Time::Local;
>
> my $date = '1999-07-03';
>
> my ( $year, $mon, $day ) = $date =~ /(\d+)/g;
> my @date_array = ( 0, 0, 0, $day, $mon - 1, $year - 1900 );
>
> print scalar( localtime( timelocal( @date_array ) ) ), "\n";
>
> my $wday = (localtime( timelocal( @date_array ) ))[6];
>
> my @start = my @end = @date_array;
>
> $start[3] -= $wday;
> $end[3]   += 6 - $wday;
>
> print scalar( localtime( timelocal( @start ) ) ), "\n";
> print scalar( localtime( timelocal( @end ) ) ), "\n";
>
> __END__
>
> John
> --
> use Perl;
> program
> fulfillment



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

Date: Tue, 14 Aug 2001 09:17:28 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Flock: Just to be sure !
Message-Id: <slrn9ni978.9fb.tadmc@tadmc26.august.net>

Mariman Center <Mariman@mariman.net> wrote:
>
>We  have  some  problems  in  a  script on a domain with high traffic,
>
>Please correct me if I make mistakes here:


You've made more than one, the primary one being that you do
not seem to have even seen the info on your very own hard disk
about file locking.

   perldoc -q lock

Oh. Too many false hits on "block", so:

   perldoc -q "\block"


      "How can I lock a file?"

      "Why can't I just open(FH, ">file.lock")?"

      "I still don't get locking.  I just want to
       increment the number in the file.  How can I do this?"



>When I want the users to only READ in a file:
>
>open (FILE, "$file");
             ^     ^
             ^     ^

You have useless double quotes there.

You should always, yes *always*, check the return value from open():

   open(FILE, $file) or die "could not open '$file'  $!";


>flock (FILE,1);
             ^

You should import the constants from the Fcntl module instead
of hard-coding them.


>#operations
>close (FILE)
>
>So, multiple users can access the file in reading, right ?


We are not talking about "users" here, we are talking about 
"programs" (actually "processes", which may be running on behalf
of some "user").

So "multiple instances of this same program can access the file 
in reading" would be correct.


>When I want one user to WRITE in a file
>open (FILE, ">>$file"); # or open (FILE, ">$file");
>flock (FILE,2);
>#operations
>close (FILE)
>
>So, NO other user may write in this file til it isn't closed, right ?


No, not right.

No other instance of a program that correctly implements file
locking may write (or read) in this file til the lock is released 
(and close()ing releases the lock).

Another program that does not do file locking correctly CAN
write to the file, probably corrupting the data. (that's
what the "merely advisory" in "perldoc -f flock" is
referring to)

So, if you are sure that _all_ programs that access this file
are locking correctly, _then_ you can say something like the above.
   

>Now,  what  happens if a file is flock (FILE,1) and that somebody else
>tries to write into it, doing a flock (FILE,2) ? In other words, the 2
>operations above, together by different users ?


It does just what the second paragraph of "perldoc -f flock" says it does:

   "Two potentially non-obvious but traditional
    "flock" semantics are that it waits indefinitely
    until the lock is granted, and that its locks
    merely advisory."

You should read the description for the functions you use. If you
don't understand something you read, you should ask about it
(mentioning where you saw it).

So what happens in the above scenario is the flock(FILE,LOCK_EX)
program hangs (waits, blocks) until the flock(FILE,LOCK_SH) 
program (and all _other_ lock holders as well) releases its lock.

ie. the writer waits until all of the readers have finished
    before it does its writing.


>Last, is it requested to write a flock (FILE,8), before closing it ?


Just the opposite!

Don't LOCK_UN yourself, just close() the filehandle.


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


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

Date: Tue, 14 Aug 2001 14:14:04 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Format error??
Message-Id: <MPG.15e2dfcaf35a51c5989740@news.edmonton.telusplanet.net>

Hi everyone,

I am encountering an error that has me stumped and would appreciate 
anyone's input on it.  Perhaps someone can see something in the code 
below off the bat.  I have tried all kinds of different things with no 
success.  I think there is something wrong with my format but in the 
documentation I have looked at it looks fine.

The relevant code (from a much larger script):

my (
  $email_address, 
  $first_name, 
  $tos_agreement_version, 
  $country, 
  $city, 
  $new_subscriber,);

format STDOUT =
@<<<<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<, @<<<<<<<<<<<
@<<<<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<
$email_address,       $first_name,       $tos_agreement_version,
$country,             $city,             $new_subscriber 
 .
# this is line 101
sub print_record
{
  my ($file_hash, $key) = @_;
  if (${$file_hash}{$key}) {
    ($email_address, $first_name, $tos_agreement_version, $country, 
$city, $new_subscriber) = split(/,/,$key.",".${$file_hash}{$key});
    print "\n";
    write(STDOUT);
  }
  else {
    print "Key not found!";
  }	 
}

Calling or not calling sub print_record makes no difference in my errors.

I get the following errors being returned....

When run from the command line with "perl db_hash.pl" I get:

Global symbol "$file_hash" requires explicit package name at db_hash.pl  
line 101.
Global symbol "$key" requires explicit package name at db_hash.pl  line 
101.

First off there is no line 101 at least in the way my db_hash.pl file 
appears in my editor.  Line 101 is just after the "." of my format and 
just before my "sub print_record" statement. Secondly I have given 
$file_hash an explicit package name through "my".

If I =pod=cut out the format my errors go away except for one about my 
format being undefined. 

When I run the file under "perl -WT db_hash.pl" I get:

Use of bar << to mean <<"" is deprecated at db_hash.pl line 97, 101, 114, 
125.

I don't even use << on lines after 101!

Any suggestions?

-- 
Carlos 
www.internetsuccess.ca 
*NOTE*: Internet Success is NOT yet fully operational 
so although you are welcomed to visit and take a 
look, trying to subscribe will only be a frustration 
for you as your data will not be saved at this time.


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

Date: Tue, 14 Aug 2001 15:28:32 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <3B792780.E59686BF@fujitsu-siemens.com>

Dave Tweed wrote:
> =

> David Combs wrote:
> > Philippe PERRIN  <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
> > >$id1 =3D "00061";
> > >print "$id1\n";    # will display 00061
> > >
> > >$id1 =3D~ s/^0*//g;
> > >print "$id1\n";    # will display 61
> > >
> >
> > Is that /g really needed, and if so, why?
> =

> Also, beware the case $id1 =3D "00000"

I do the very same thing when building index pages for my digital camera
pictures:

	($n =3D $1) =3D~ s/^0*(\d)/\1/;

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: 14 Aug 2001 13:38:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <9lb9la$8oj$2@mamenchi.zrz.TU-Berlin.DE>

According to Josef Moellers  <josef.moellers@fujitsu-siemens.com>:
> Dave Tweed wrote:
> > 
> > David Combs wrote:
> > > Philippe PERRIN  <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
> > > >$id1 = "00061";
> > > >print "$id1\n";    # will display 00061
> > > >
> > > >$id1 =~ s/^0*//g;
> > > >print "$id1\n";    # will display 61
> > > >
> > >
> > > Is that /g really needed, and if so, why?
> > 
> > Also, beware the case $id1 = "00000"
> 
> I do the very same thing when building index pages for my digital camera
> pictures:
> 
> 	($n = $1) =~ s/^0*(\d)/\1/;
                               ^^

Don't use \1 etc on the replacement side of s///.  Since that is outside
the regex, $1 should be used.

The real solution for number formatting is, of course, sprintf, and
not an ad-hoc regex that may or may not do the job.

    $n = sprintf '%d', $1;

sprintf gives you access to a whole library of specialized formatters.
Use them.

Anno


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

Date: Tue, 14 Aug 2001 09:19:21 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <slrn9ni9ap.9fb.tadmc@tadmc26.august.net>

Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
>David Combs wrote:
>> >$id1 =~ s/^0*//g;
>> >print "$id1\n";    # will display 61
>> >
>> 
>> Is that /g really needed, and if so, why?
>
>no it isn't... it's a mistake. since the ^0* already deletes all leading
>zeros, there's no need to put a /g (global) option. just keep
>$id1 =~ s/^0*//;


Why bother with deleting zero instances of the zero character?

   $id1 =~ s/^0+//;


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


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

Date: Tue, 14 Aug 2001 15:58:14 +0200
From: Timo Trinks <trinks@prolink.de>
Subject: grep 5th word in a text-file
Message-Id: <3B792E76.C682E713@prolink.de>


hi.

i'm trying to code a script that reads the 5th word of a line and writes
it to stdout:

radius log report for: foo

so foo is the word to be extracted from a logfile and to be written to
stdout or to another file.

i tried sth like my $word =3D (split ' ', $1)[4]; but unsuccessfully...
so any ideas ?

tia,

Timo
-- =

aka t=B2 .oO http://www.trinks.net/cv.php Oo.


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

Date: 14 Aug 2001 14:09:14 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: grep 5th word in a text-file
Message-Id: <slrn9nicif.qkd.rgarciasuarez@rafael.kazibao.net>

Timo Trinks wrote in comp.lang.perl.misc:
> 
> i'm trying to code a script that reads the 5th word of a line and writes
> it to stdout:
[...]
> i tried sth like my $word = (split ' ', $1)[4]; but unsuccessfully...
> so any ideas ?

You've made a mistake; replace $1 by $_ or by whatever variable holds
the current line.

Here's the one-line version :
    perl -lne 'print((split)[4])' file

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


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

Date: 14 Aug 2001 09:17:25 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: How do I assing an entire array?
Message-Id: <9lb8d5$gd3$1@panix2.panix.com>

In <patgnts5uupfbgk6k0ugp6n9brd4bpirq2@4ax.com> Bart Lateur <bart.lateur@skynet.be> writes:

>Stan Brown wrote:

>>>$cols{$f_keys[0]}{'SRC_COLS'} = \@p_keys; # or: $... = [ @p_keys ];
>>
>>Thaks, I thought of that, but what if @p_keys goes out of scope by the time
>>I need it?

>That's good.

>You can keep a reference to a  variable in a hash, and when the variable
>goes out of scope, the hash is the only way left to access it. Until you
>get rid of the reference in the hash, the variable's value itself will
>not be destroyed, although the variable itself is gone.

Thanks.

Hey Toto, I don't think we are in C anymore :-(


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

Date: Tue, 14 Aug 2001 13:33:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How do I assing an entire array?
Message-Id: <nv9int8acm2do74mieul0h0fffc8jd7eno@4ax.com>

Stan Brown wrote:

>>You can keep a reference to a  variable in a hash, and when the variable
>>goes out of scope, the hash is the only way left to access it. Until you
>>get rid of the reference in the hash, the variable's value itself will
>>not be destroyed, although the variable itself is gone.
>
>Thanks.
>
>Hey Toto, I don't think we are in C anymore :-(

Why the ":-("? You think that's bad? I think it's a very good thing: as
long as one thing (say, a variable) is hanging on to the data, it won,'t
be destroyed. It's extremely handy. Neither dangling pointers nor memory
leaks.

The only thing you have to watch out for, are circular references, where
A contains a reference to B, and B a reference to A. But those are not
that common, except if you try to create a bidirectionally walkable
tree. Er... where you can go just as easily from top to bottom as from
bottom to top.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 14:58:32 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: modules and variables
Message-Id: <3B8276D5.51A6DB30@sprintmail.com>

  I have a few functions that I've moved into a module. I'm unsure how
to initialize/reset global variables for these functions. 

  Here's what I have:

use myModule($enviornment_var1,$enviornment_var2);

and "myModule"
*********************
my($env1,$env2)=@_;
 ...

That seems a little funky to me (I can't quite make sense of "perlmod"
yet).

How do I refer to these module variables so I can change them later? Is
there a better way to initialize the module? A little bit of actual code
would help a lot.

  Jeff


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

Date: 14 Aug 2001 13:06:30 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: Passing parameters to subroutines
Message-Id: <slrn9nhmq0.u9j.trammell@haqq.hypersloth.net>

On Tue, 14 Aug 2001 08:54:00 -0400, Glenn <glenn@surveystar.com> wrote:
> I'm  confused about how passing parameters works in Perl 5.  Here's my
> test program...
> 
>     &SUB1(21);  #call first subroutine with some value
> 
>     sub SUB1 {
>     my $passed1=$_[0];
>     print "<br>passed1 is: $passed1 ";
>     &SUB2;  #call 2nd subroutine with no passed value
>     }
> 
>     sub SUB2 {
>     my $passed2=$_[0];                         # should be NULL if
> nothing passed to SUB2, right?
>     print "<br>passed2 is: $passed2 ";
>     }
> 
> ...my output is...
>     passed1 is: 21
>     passed2 is: 21
> 
> Why does $passed2 get the value of $passed1?  This happens unless I call
> SUB2 with an empty parameter list like &SUB2();

This is documented in perlsub.  'man perlsub', 'perldoc perlsub',
whichever.

-- 
Salad: it's what's for dinner, for what's for dinner.


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

Date: Tue, 14 Aug 2001 13:09:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Passing parameters to subroutines
Message-Id: <9k8intk1o2bmqhbsejbrel526g7kimbona@4ax.com>

Glenn wrote:

>Why does $passed2 get the value of $passed1?  This happens unless I call
>SUB2 with an empty parameter list like &SUB2();

Exactly. Do NOT call SUB2 using a bare &SUB2 unless you want (or do not
mind) to retain the sub arguments (@_) from the caller. See perlsub (via
perldoc or as HTML files) for detailed info.

-- 
	Bart.


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

Date: 14 Aug 2001 06:15:32 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <74f348f7.0108140515.5344fc43@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9n2gsj.mbp.tadmc@tadmc26.august.net>...

> As Eric has mentioned, the Perl docs should document Perl. Other
> docs should document programming fundamentals.
 ... 
> Learning programming AND Perl at the same time will be much much
> harder than learning either one by itself.

I dont agree with this.  I think Perl has many characteristics that
make it a good 'teaching language' on the other hand it has a few
(usually relatively easy to work around) traits that perhaps could
lead to bad habits :-)  And to back up my belief I will paraphrase
(through a distoted memory) Larry Wall (i think from the State of the
Onion speech): One of the traits of perl is that, like human
langauges, it should be usable by those that only know a little, but
also powerfull for those that know more.

It seems to me that there is a call for a document like perllearn or
something that could serve as a intro-to-comp-sci type tutorial using
perl.

I mean not to be funny, but I know of more than a few people who have
been quite successful with only the knowledge available from things
like the VB help docs.  Of course at a certain point they realized
that they needed more comprehensive texts and so obtained them.  But
the point is still valid.

Yves


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

Date: 14 Aug 2001 07:10:58 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <74f348f7.0108140610.39856330@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9n34mg.nit.tadmc@tadmc26.august.net>...
> Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
> >In article <slrn9n2gsj.mbp.tadmc@tadmc26.august.net>, Tad McClellan at 
> >tadmc@augustmail.com says...

> >I certainly wouldn't call regular expressions 
> >something that is a programming fundamental.  
>
> Regular grammars are certainly a programming fundamental.

Absolutely.  But then they are also fundamental to mathematics and to
a certain degree even philosophy.

> 
> Regular expressions correspond to regular grammars.

This is easy for you and me to see, but we have a comp-sci viewpoint.
I think a lot of people would understand the concept of formal
grammers, but not really get regular expressions.  If only because the
notation of one is fairly intuitive, where the other is, well, not.  I
have often thought that teaching regular expressions without _ever_
using that term might be a good idea.  For instance the term template
might be used to avoid unnecessary confusion.

Also, to get picky, strictly speaking Perls regexes are _not_ regular.
(yeah yeah, you said correspond because of this point, but it _should_
be said) Simply by including back refrences means that the perl
regular expressions cannot be considered to be formally regular, not
to mention various other aspects of the perl regex syntax. (Come to
think of it, I am sure i have seen something somewhere (maybe a faq)
that says that perl syntax in general is not propperly speaking
regular either.)

Yves


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

Date: Tue, 14 Aug 2001 14:51:32 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: Possible perl/DOS bug?
Message-Id: <9lb6k70qgf@enews3.newsguy.com>


"Jonas Nilsson" <nospam.jonni@ifm.liu.se> wrote in message
news:9lb4ou$6tm$1@newsy.ifm.liu.se...
> use strict;
> my $mydir='D:/Slask/testdir/';

> mkdir($mydir."testdir1../");
> mkdir($mydir."testdir2..\\");
(above two lines are equivalent)

I do not think it is a perl bug but a dos file system weirdness.  If you try
something of the sort using some other programming language you will
probably get the same.  To 'view' and 'delete' those folder names from
console (not explorer) you have to view the folders with their 8.3 filename
format.
e.g:

dir /x
rd testdi~2

B






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

Date: 14 Aug 2001 06:29:53 -0700
From: mike_solomon@lineone.net (Mike Solomon)
Subject: printing from windows (gdi32)
Message-Id: <56568be5.0108140529.259a7692@posting.google.com>

I am trying to write a script to print a file under a windows
enviroment.

I have looked at previous messages on this subject and have taken some
code posted in the past have come up a script that does most of what i
want.

unfortunately I can't work out how to change the orientation of the
printer from the script to landscape.

any suggestion will be gratefully received.

the code i have come up with so far is as follows:

use strict;
use diagnostics;
use Win32::API;

# printer name exactly as it appears in the "printers" window
my $printername ="Lexmark 3200 Series ColorFine";   

#file to print
my $filename = "test.txt";
my $fontsize = 12;
my $font_type = "Fixedsys";

# API declarations:
my $CreateDCforPrinter = new Win32::API('gdi32',"CreateDC", [qw'N P N
N'], 'N');
my $DeleteDC = new Win32::API("gdi32","DeleteDC",['N'], 'N');
my $StartDoc = new Win32::API('gdi32',"StartDoc", [qw'N P'], 'N');
my $EndDoc = new Win32::API('gdi32',"EndDoc", ['N'], 'N');
my $StartPage = new Win32::API('gdi32',"StartPage", ['N'], 'N');
my $EndPage = new Win32::API('gdi32',"EndPage", ['N'], 'N');
my $GetDeviceCaps = new Win32::API('gdi32',"GetDeviceCaps", [qw'N N'],
'N');
my $CreateFont = new Win32::API('gdi32',"CreateFont", [('N') x 13,
'P'], 'N');
my $SelectObject = new Win32::API('gdi32',"SelectObject", [qw'N N'],
'N');
my $DeleteObject = new Win32::API('gdi32',"DeleteObject", ['N'], 'N');
my $TextOut = new Win32::API('gdi32',"TextOut", [qw'N N N P N'], 'N');
my $GetTextExtentPoint32 = new Win32::API('gdi32',
'GetTextExtentPoint32', [qw'N P N P'], 'N');

#print section

if(my $hdc = $CreateDCforPrinter->Call(0, $printername, 0, 0)) {
	my $jobname = "Printer Test";
	my $docinfo = pack 'VpV', 12, $jobname, 0;

	if($StartDoc->Call($hdc, $docinfo) && $StartPage->Call($hdc)) {
		my($HORZRES, $VERTRES, $LOGPIXELSY) = (8, 10, 90);
		my $horzres = $GetDeviceCaps->Call($hdc, $HORZRES);
		my $vertres = $GetDeviceCaps->Call($hdc, $VERTRES);
		my $dpi = $GetDeviceCaps->Call($hdc, $LOGPIXELSY);

		# Font 
		my $newfont = $CreateFont->Call($fontsize*$dpi/72, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, $font_type);
		my $oldfont = $SelectObject->Call($hdc, $newfont);           

		open FILE, $filename or die "Can't open $filename";

		my $line = 0;
		my $height = $fontsize*$dpi/72*1.03;
		my $lines_per_page = int($vertres/$height) -1;

		while (<FILE>) {
			#call start page if line == 0
			$StartPage->Call($hdc) if $line == 0;

			chomp;					#strip newline

			my $text = $_;
		
			$text =~ s/\t/    /g;		#replace tabs with "    "

			#print
			$TextOut->Call($hdc, 100, ++$line * $height, $text, length($text));

			#page break
			if ($line == $lines_per_page) {
				$EndPage->Call($hdc);
				$line = 0;
			}

		} #end of file

		#I presume next line replaces new printer settings with original
settings
		$SelectObject->Call($hdc, $oldfont);
		#delete new settings
		$DeleteObject->Call($newfont);
		#end printing and eject paper
		$EndPage->Call($hdc) and $EndDoc->Call($hdc);
	}
	#Delete DC - ???
	$DeleteDC->Call($hdc);
} else {   die "No DC for printer. Printer name wrong?"; }


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

Date: 14 Aug 2001 14:00:54 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: printing from windows (gdi32)
Message-Id: <9lbaum$3u6$2@bob.news.rcn.net>

Mike Solomon <mike_solomon@lineone.net> wrote:
> I am trying to write a script to print a file under a windows
> enviroment.

> I have looked at previous messages on this subject and have taken some
> code posted in the past have come up a script that does most of what i
> want.

> unfortunately I can't work out how to change the orientation of the
> printer from the script to landscape.

You need to pass the address of a DEVMODE structure as the fourth 
parameter to CreateDC, and set its dmOrientation field to 
DMORIENT_LANDSCAPE.



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

Date: Tue, 14 Aug 2001 09:16:57 -0400
From: A person <strawSPAM_BEGONEman@plexi.com>
Subject: Re: regex question...
Message-Id: <3B7924C9.927AA355@plexi.com>

Ren Maddox wrote:

> On Mon, 13 Aug 2001, strawSPAM_BEGONEman@plexi.com wrote:
>
> > What is the < in:
> > s#(?<=\[)(\d*)(?=\])#$1-1#ge
> > for?
>
> It is part of (?<=...), which is an advanced regex feature documented
> in perlre(1).  It is a zero-width look-behind assertion, which means
> that it looks backwards in the string and matches the contained
> pattern.  This sub-match is not considered a part of the overall
> match, which allows the substitution to ignore it.

snip...


perlre is very interesting reading. The < threw me because I was unaware
of the distinction between look-ahead and look-behind. I guess this is
really a question for the implementors (you may be one for all I know) ,
but isn't its position in the regular expression itself enough to imply
whether a (?<=.) or a (?=.) is look-ahead or look-behind?


Thanks again sharing.



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

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


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