[11552] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5153 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 16 23:07:20 1999

Date: Tue, 16 Mar 99 20:02:30 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 16 Mar 1999     Volume: 8 Number: 5153

Today's topics:
    Re: DUMB Newbie question (Tad McClellan)
    Re: Finding end of line <rick.delaney@home.com>
    Re: flock() on NT? (Michael Budash)
    Re: Help...this worked under 4.036 but doesn't under 5. (Kevin Reid)
        How to get a long filename from a shortened one? <seannln@bit-net.com>
    Re: how to include a init table file without complainin (Tad McClellan)
    Re: HTML, RTF, XML and CGI (William Herrera)
    Re: Need Faster Approach (George)
    Re: Problem passing block and array reference to subrou (Andrew Johnson)
    Re: Problem passing block and array reference to subrou <boldts@korax.net>
        problem with scoping using strict no refs (Tim Speevack)
    Re: problem with scoping using strict no refs <ebohlman@netcom.com>
    Re: problem with scoping using strict no refs <rick.delaney@home.com>
    Re: problem with scoping using strict no refs (Ronald J Kimball)
    Re: Pushing current line back onto <FILE> (William Herrera)
    Re: Regex limits for regex/function calls within subsit (Abigail)
        RE: Send Form Data to the end of a URL within the HTML  <shawncarpenter@MailAndNews.com>
        Syntax help needed!  References to filehandles and <>. (Clinton Pierce)
    Re: Syntax help needed!  References to filehandles and  <ebohlman@netcom.com>
    Re: Syntax help needed!  References to filehandles and  (Ronald J Kimball)
        Unicode/Base64 ? (Michael Kagalenko)
    Re: Using Select on STDIN ??? (Ronald J Kimball)
    Re: Using the print << command (George Crissman)
    Re: viewing contents of *.html files (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 16 Mar 1999 11:55:22 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: DUMB Newbie question
Message-Id: <qd2mc7.bj8.ln@magna.metronet.com>

VisualJP (visualjp@aol.com) wrote:
: I am trying to start a perl script on a SGI (irix).  It contains a loop that
: executes a program.  The problem is that the perl script doesn't seem to wait
: until the program finishes, it just keeps going.  The result is the same
: program opened several times at once.  


   You have an error on line 17.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 17 Mar 1999 00:55:32 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Finding end of line
Message-Id: <36EEFF76.5B8F822C@home.com>

[posted & mailed]

Jay Glascoe wrote:
> 
> "J|rgen Exner" wrote:
> >
> > However there is a
> > - line-feed character (LF)
> 
> ascii value 12 <=> "\f" <=> "\014" <=> aka <ctrl-M>

This is a formfeed character.  And it's ctrl-L.

> 
> > - and a carriage return character (CR)
> 
> ascii value 13 <=> "\r" <=> "\015"

This is ctrl-M.

> 
> - and a newline character
> 
> ascii value 10 <=> "\n" <=> "\012"

Linefeed.  Ctrl-J.  Newline and linefeed happen to be the same on
Unix-ish systems.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 16 Mar 1999 17:41:01 -0800
From: mbudash@trantracks.com (Michael Budash)
Subject: Re: flock() on NT?
Message-Id: <mbudash-1603991741010001@d30.nas1.napa.sonic.net>

In article <l9zmOU$b#GA.171@rejz.ij.net>, ehpoole@ingress.com (Ethan H.
Poole) wrote:

>[Posted and Emailed]  In article 
><mbudash-1603991220530001@d58.nas1.napa.sonic.net>, mbudash@trantracks.com 
>says...
>>
>>i'm pretty sure flock() won't work on nt systems... am i correct?
>>
>>so what do youz guys use in such dire (read that: micro$oft) predicaments?
>
>I haven't found the flock() function to be very reliable under NT (NT 
>certainly has the native capability to lock files *very* effectively, but the 
>Perl implementation does not seem to take advantage of this), particularly on 
>multi-processor machines.  I should point out that I have not tested flock() 
>under the latest Perl release.

thanks, that's good to know...

anybody else have similar experiences?

>You can always fall back on the old trick of using *.lok files
[snip]

if you're suggesting what i think you're suggesting, i humbly advise that
you read the perl faq's section entitled:

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

you will see why that method is not to be advised...
-- 
@-----------------------------@--------------------@
| Michael Budash Consulting   | 707-255-5371       |
| Perl, Javascript, Html      | 707-258-7800 x7736 |
| Official Extropia Developer | mbudash@sonic.net  |
@-----------------------------@--------------------@


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

Date: Tue, 16 Mar 1999 22:45:14 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Help...this worked under 4.036 but doesn't under 5.x
Message-Id: <1doq6hz.1p2imwhjsdedmN@[192.168.0.1]>

Oskar Itzinger <oskar@opec.org> wrote:

> Under Perl 4.0.36, the following piece of code worked
> and would set eg, with an argument of -xac, both variables
> $A and $AC:
<snip>
> Under Perl 5.x, only variable $A is set.
> 
> What changed in Perl 5.x which causes the different
> behavior?

In addition to Bart Lateur's explanation of the problem, you might be
interested in this cleaner (IMHO) version of your code:

@keys = qw(a ab ac ad);

foreach (@ARGV) {
  /^-(.*)$/ or last;
  if ($1 =~ /^x(.*)$/) {
    my $sw = $1;
    foreach (@keys) {
      ${uc $_}++ if $sw =~ /^$_/;
    }
  }
}

-- 
 Kevin Reid: |    Macintosh:      
  "I'm me."  | Think different.
    


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

Date: Tue, 16 Mar 1999 22:23:41 -0500
From: Sean Phillips <seannln@bit-net.com>
Subject: How to get a long filename from a shortened one?
Message-Id: <36EF203C.226210D4@bit-net.com>

Windows NT/Perl question:
When you drag-n-drop a file onto a Perl program on the desktop the OS
feeds the filename to $ARGV[0].   Unfortunately, it will use the short
(8.3) filename.
Is there any way to translate it back to the long filename?

I've tried a pipe from the command "dir /N $shortfilename" and while
that fixes the filename itself, the directory is still mangled.   The
utilities in Cwd don't seem to help either.

Life was easier programming in UNIX...

Thanks in advance,
- Sean



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

Date: Tue, 16 Mar 1999 11:52:52 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to include a init table file without complaining from "use strict"
Message-Id: <492mc7.bj8.ln@magna.metronet.com>

Tungning Cherng (cherng@uuman.bbn.com) wrote:

: However, I have a very large initialized table, would like to separate into
: an individual file.  

: For example, Two files: a.pl ad b.pl.

: % cat a.pl
: my %largeTable=(
  ^^
  ^^

   You have restricted the scope here...


:    'a' , '1',
:    'b' , '2',
: );

: % cat b.pl
: use strict;
: require "a.pl";
: print "$largeTable{'a'}\n";


   ... so %largeTable is not visible here.


: Now run "perl b.pl", I got an error:
:     Global symbol "largeTable" requires explicit package name ...

: I have to remove "use strict" line, and use global variable to make it work.
: I don't think it is the right way.

: Could some one tell me how to solve the problem by using "use strict"?


==> a.pl <==

%largeTable=(
   'a' , '1',
   'b' , '2',
);



==> b.pl <==
#!/usr/bin/perl -w

use strict;
use vars '%largeTable';     # declare the global variable

require "a.pl";
print "$largeTable{'a'}\n";


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 17 Mar 1999 02:37:22 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: HTML, RTF, XML and CGI
Message-Id: <36ef1484.164995219@news.rmi.net>

On Tue, 16 Mar 1999 21:16:07 +0300, "Michael Yevdokimov"
<flanker@sonnet.ru> wrote:

>Have you received an answer?
>I'd like to get a Perl script for parsing RTF file (to convert it into
>HTML)... My scripts works under FreeBSD system and I don't need in C
>programes!
>
>If you have or anyone else have, please let me know as soon as possible. ;-)

Try http://www.cpan.org/modules/by-module/RTF/

Though frankly I think it is buggy. I have several valid RTF text
files that put in into an endless loop :(.  For most things it is
okay.



---
The above from: address is spamblocked. Use wherrera (at) lynxview (dot) com for the reply address.


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

Date: Tue, 16 Mar 1999 20:35:05 -0500
From: fred222@mauimail.com (George)
Subject: Re: Need Faster Approach
Message-Id: <fred222-ya023580001603992035050001@news.bellatlantic.net>

> Suppose a long comma-delimited string (say 100,000 items for the sake of
> argument).  Now suppose you want to grab 50 items from the middle of this
> string (like if you're displaying search results 50 at a time).  Does anyone
> out there have a particularly speedy approach to this problem?  Right now I
> am reading all 100,000 items into an array by using 'split' on the comma
> delimiter, then I'm using 'splice' to grab my 50 result items into a
> "results" array.

One way I've heard of would be to make each item in the array a set length
(so you know each line will be X bytes) and then use the
seek(DAT,initial_num*X,0);
command to go to the beginning of where you want to read, then to read the
next end_num*X bytes, then close the file.  I'm afraid I'm not so hot at
seek and so forth, I'm somewhat of a newbie and haven't really fully gulped
down all there is to know yet, but there's the idea behind it.  Good luck,
and if you ever get some working code I would appreciate seeing it (I've
got an internal search engine going for my site, it sifts through
parameters for over 2,000+ jokes, and pruning down the several-seconds time
it takes to read all the files and split 'em would be great!

If so, my email is yurtle@bellatlantic.net

Best regards,
George Henry

-- 
Just another hacking head >l-d


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

Date: Wed, 17 Mar 1999 00:05:04 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Problem passing block and array reference to subroutine
Message-Id: <QkCH2.3574$uw1.7019@news1.rdc1.on.wave.home.com>

In article <36EEEF20.22FAF333@korax.net>,
 Hans Boldt <boldts@korax.net> wrote:
! Greetings!  I did try looking in the docs for an answer, but 
! I'm stumped.  (Not hard, since I haven't been programming in
! Perl for long.)  The following code works:
! 
! ----------------
! sub testing (&\@)
! {
!    my ($proc, $arr) = @_;
!    print "@$arr\n";
!    &$proc;
! }
! 
! @array = ('a', 'b', 'c');
! testing
! {
!    print "in testing\n";
! }
! @array;
! ----------------
! 
! The following doesn't, and I've tried all manner of variations.
! I would prefer to be able to code the reference to the array
! as the first parameter to the subroutine, but nothing I've 
! tried works.  I'm using 5.004-6.  Any thoughts would be greatly 
! appreciated.
! 
! ----------------
! sub testing (\@&)
! {
!    my ($arr, $proc) = @_;
!    print "@$arr\n";
!    &$proc;
! }
! 
! @array = ('a', 'b', 'c');
! testing \@array,
! {
!    print "in testing\n";
! };

(I assume you meant 'testing @array' not 'testing \@array' above)

from the perlsub manpage:
       Unbackslashed prototype characters have special meanings.
       Any unbackslashed @ or % eats all the rest of the
       arguments, and forces list context.  An argument
       represented by $ forces scalar context.  An & requires an
       anonymous subroutine, which, if passed as the first
       argument, does not require the "sub" keyword or a
       subsequent comma.  A * does whatever it has to do to turn
       the argument into a reference to a symbol table entry.

thus, if not passed as the first arg, requires the sub keyword:

sub testing (\@&)
{
   my ($arr, $proc) = @_;
   print "@$arr\n";
   &$proc;
}

@array = ('a', 'b', 'c');
testing @array, sub
{
   print "in testing\n";
};      

hope that helps
regards
andrew


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

Date: Wed, 17 Mar 1999 00:21:15 GMT
From: Hans Boldt <boldts@korax.net>
Subject: Re: Problem passing block and array reference to subroutine
Message-Id: <36EEF566.DB817711@korax.net>

Andrew Johnson wrote:
> 
> (I assume you meant 'testing @array' not 'testing \@array' above)
> 
> from the perlsub manpage:
>        Unbackslashed prototype characters have special meanings.
>        Any unbackslashed @ or % eats all the rest of the
>        arguments, and forces list context.  An argument
>        represented by $ forces scalar context.  An & requires an
>        anonymous subroutine, which, if passed as the first
>        argument, does not require the "sub" keyword or a
>        subsequent comma.  A * does whatever it has to do to turn
>        the argument into a reference to a symbol table entry.
> 
> thus, if not passed as the first arg, requires the sub keyword:
> 
> sub testing (\@&)
> {
>    my ($arr, $proc) = @_;
>    print "@$arr\n";
>    &$proc;
> }
> 
> @array = ('a', 'b', 'c');
> testing @array, sub
> {
>    print "in testing\n";
> };
> 
> hope that helps
> regards
> andrew

Thanks!  That was fast!  Darn, I was looking right at that
paragraph in the docs, and it didn't sink in at all!  I just
tried adding the 'sub' and it works now.

Cheers!  Hans
-- 
http://www.korax.net/~boldts/


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

Date: Wed, 17 Mar 1999 01:28:26 GMT
From: speevack@ix.netcom.com (Tim Speevack)
Subject: problem with scoping using strict no refs
Message-Id: <7cn0g0$m48@dfw-ixnews8.ix.netcom.com>

I have an (unpredictable) series of name/value pairs stored in a database.
I need to extract these pairs from the database and dynamically create 
variables of the same name as the 'name' column from the database.

If I don't use strict, this works fine:
        ${$name_from_database} = $value_from_database;
Assuming the name/value from the database was "foo" and "bar" respectively, 
the statement above would create the variable $foo = "bar".  No problem.

If I use strict it won't allow me to "use string  ("foo") as a SCALAR ref 
while "strict refs" in use".  To get around that error I added 'no strict 
refs'.

After adding 'no strict refs', it allows the statement, but the assignment 
doesn't happen, I assume because of scoping, but I really don't understand 
what's happening.  

Here's a script which demonstrates what I'm trying to accomplish, though it 
doesn't work.  Anyone have any ideas?  (Feel free to tell me I'm going about 
this the wrong way).

#!perl
use strict;
no strict 'refs';

# normally this is populated from the database, but for
# this demo, I'll populate it manually:
my @dbvariables = ();
$dbvariables[0] = { "name","var_one","value","1" };
$dbvariables[1] = { "name","var_two","value","2" };

# These are the variables I need to create dynamically.
# my goal is to NOT create them here, but I've been
# trying lots of variations on this theme.
my $var_one;
my $var_two;

for my $record ( @dbvariables ) {
  print "record contains: $record->{name} = $record->{value}\n";

  # create $var_one = 1, e.g.:
  ${$record->{name}} = $record->{value};

  print "in loop, var_one = [$var_one]\n";
  print "in loop, var_two = [$var_two]\n";
}

print "after var_one = [$var_one]\n";
print "after var_two = [$var_two]\n";

--------------------------------------------------------------------------
Tim Speevack, Advantix, Inc.
tms@advantix.com


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

Date: Wed, 17 Mar 1999 02:09:24 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: problem with scoping using strict no refs
Message-Id: <ebohlmanF8pvBo.208@netcom.com>

Tim Speevack <speevack@ix.netcom.com> wrote:
: I have an (unpredictable) series of name/value pairs stored in a database.
: I need to extract these pairs from the database and dynamically create 
: variables of the same name as the 'name' column from the database.

No, you may *want* to dynamically create variables using symbolic 
references, but you don't *need* to.  You can just as easily use a hash.



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

Date: Wed, 17 Mar 1999 02:29:25 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: problem with scoping using strict no refs
Message-Id: <36EF1576.51807EE6@home.com>

[posted & mailed]

Tim Speevack wrote:
> 
> I need to extract these pairs from the database and dynamically create
> variables of the same name as the 'name' column from the database.

You should never need to do that.

[snip]
> 
> Here's a script which demonstrates what I'm trying to accomplish, 
> though it doesn't work.  Anyone have any ideas?  (Feel free to tell me 
> I'm going about this the wrong way).

Okay, what you should be doing is using a plain ol' hash.

> 
> #!perl
> use strict;
> no strict 'refs';
> 
> # normally this is populated from the database, but for
> # this demo, I'll populate it manually:
> my @dbvariables = ();
> $dbvariables[0] = { "name","var_one","value","1" };
> $dbvariables[1] = { "name","var_two","value","2" };
> 
> # These are the variables I need to create dynamically.
> # my goal is to NOT create them here, but I've been
> # trying lots of variations on this theme.
> my $var_one;
> my $var_two;

Get rid of these.

my %poh;
@poh{qw/var_one var_two/} = ();

> 
> for my $record ( @dbvariables ) {
>   print "record contains: $record->{name} = $record->{value}\n";
> 
>   # create $var_one = 1, e.g.:
>   ${$record->{name}} = $record->{value};

Here you assign to the global variables $var_one and $var_two.  They are
different than the local variables $var_one and $var_two that you
declared with my above.

Don't use those when you can just do this:

    $poh{ $record->{name} } = $record->{value};

> 
>   print "in loop, var_one = [$var_one]\n";
>   print "in loop, var_two = [$var_two]\n";

You have two $var_one's and two $var_two's.  When you write "$var_one"
here, the local gets precedence.  So you get its value which is undef. 
To access the global's value, you can write "${'var_one'}" since it can
be accessed using a symbolic ref.

But never mind that.  Just do this:

    print "in loop, poh{var_one} = [$poh{var_one}]\n";
    print "in loop, poh{var_two} = [$poh{var_two}]\n"; 

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 16 Mar 1999 22:20:33 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: problem with scoping using strict no refs
Message-Id: <1dos47y.134ezvk1q0ykecN@bay1-411.quincy.ziplink.net>

Tim Speevack <speevack@ix.netcom.com> wrote:

> # These are the variables I need to create dynamically.
> # my goal is to NOT create them here, but I've been
> # trying lots of variations on this theme.
> my $var_one;
> my $var_two;

Symbolic references and lexical variables don't mix.
If you want to refer to these variables symbolically,
you cannot declare them with my().

-- 
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
    perl -e'for(sort keys%main::){print if $$_ eq 1}
        ' -s  -- -' Just' -' another ' -'Perl ' -'hacker 
' http://www.ziplink.net/~rjk/  [rjk@linguist.dartmouth.edu]


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

Date: Wed, 17 Mar 1999 02:25:59 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: Pushing current line back onto <FILE>
Message-Id: <36ef1170.164207359@news.rmi.net>

On 15 Mar 1999 17:00:25 -0500, jete@dgs.dgsys.com (Jete Software Inc.)
wrote:

>I need to push the current line back onto the <FILE> file handle
>
>open(FILE, "/tmp/junk") || die "Can't open /tmp/junk";
>
my ($lastTell)  = 0;
>while <<FILE>) {
>
>	if (something) {
>	   #	push $_ back onto <FILE>;
                           seek(FILE, $lastTell, 0);
>		last;
>	}
             else
             {
               $lastTell = tell(FILE);
             }
>}


---
The above from: address is spamblocked. Use wherrera (at) lynxview (dot) com for the reply address.


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

Date: 17 Mar 1999 02:10:10 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Regex limits for regex/function calls within subsitutions?
Message-Id: <7cn2u2$k3j$1@client2.news.psi.net>

Burton Kent (burton.not.spam@lucent.com) wrote on MMXXIII September
MCMXCIII in <URL:news:36EE8802.CDDE808F@lucent.com>:
() What kind of limits does Perl have on substitutions?  

Things like /foo+/ don't allow more than 32k foo's, for non-trivial foo's.
There used to be a limit on the size of the compiled regex, but I don't
know if that limit is still there.

() Is there anything I should watch out for in substitutions?
() (e.g. $text =~ s/this/that/g;)
() 
() I get a segmentation fault at a consistent place in a 
() substitution operation -- at the end of the replace.  I'm
() able to print the value right before returning from the 
() replace, but get the segmentation fault as the replace 
() returns.

A segmentation fault from perl is always a bug in perl. If you have a
current version of perl, please write a small program exhibiting this
behaviour and use 'perlbug' to report it.

() Has anyone else had similar problems?  


Maybe, maybe not. But you don't show us any code....




Abigail
-- 
perl -wlpe '}$_=$.;{' file  # Count the number of lines.


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

Date: Tue, 16 Mar 1999 19:14:04 -0500
From: Shawn Carpenter <shawncarpenter@MailAndNews.com>
Subject: RE: Send Form Data to the end of a URL within the HTML output
Message-Id: <7cms4m$j31$1@client2.news.psi.net>

Only problem is I don't know how to set up the script...  any ideas???

>===== Original Message From Ben Gertzfield  =====
>>>>> "Shawn" == Shawn Carpenter  writes:
>
>    Shawn> I would like to set up a form with in an HTML file that
>    Shawn> would allow users to enter a stock symbol like MSFT and
>    Shawn> then execute a script that would send MSFT to the end of
>    Shawn> several URL's in the HTML output file.
>
>Great! Go to it.
>
>Ben
>
>--
>Brought to you by the letters T and N and the number 8.
>"Ooh, don't touch him, HE'S got the wall sconses."
>Debian GNU/Linux maintainer of Gimp and GTK+ -- http://www.debian.org/
>I'm on FurryMUCK as Che, and EFNet/Open Projects IRC as Che_Fox.

------------------------------------------------------------
Shawn Carpenter
WallStreetView.com
http://www.wallstreetview.com
------------------------------------------------------------



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

Date: Wed, 17 Mar 1999 01:21:19 GMT
From: clintp@geeksalad.org (Clinton Pierce)
Subject: Syntax help needed!  References to filehandles and <>.
Message-Id: <36eef9e5.201533028@news.roalok1.mi.home.com>

I've created a FileHandle object, and placed it inside of a hash
(error checking omitted for snippets, it's there though):

sub go_open_a_file {
	$fh= new FileHandle "/tmp/myfile", "r";
	return({
		name=>"/tmp/myfile",
		handle=>$fh,
		otherstuff=>$other_cool_things,
		});
}

Later on, I've got a reference to the above structure being passed
around, so that:

	$$fstruct{handle}

Refers to the FileHandle object.  Question...how do I READ it?  Perl
doesn't like:

	<$$fstruct{handle}>    #  Doesn't seem to know this?

or...
	<$$$fstruct{handle}>   # Doesn't like this at all.

 ...but if I say...

	$foo=$$fstruct{handle};
	$line=<$foo>;

Perl's happy, and it does the Right Thing.  But the temporary variable
is there because of (apparent) syntatic nonsense that I haven't quite
grokked.  Can anyone explain the correct way to read this
"$$fstruct{handle}" and why?  Am I missing curlies somewhere?  Help.

-- 
"If you rush a Miracle Man, you get rotten miracles"
                     --Miracle Max, The Princess Bride
http://www.geeksalad.org


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

Date: Wed, 17 Mar 1999 02:04:09 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Syntax help needed!  References to filehandles and <>.
Message-Id: <ebohlmanF8pv2x.1rH@netcom.com>

Clinton Pierce <clintp@geeksalad.org> wrote:
: I've created a FileHandle object, and placed it inside of a hash
: (error checking omitted for snippets, it's there though):

[snip]
: Later on, I've got a reference to the above structure being passed
: around, so that:

: 	$$fstruct{handle}

: Refers to the FileHandle object.  Question...how do I READ it?  Perl
: doesn't like:

: 	<$$fstruct{handle}>    #  Doesn't seem to know this?

: or...
: 	<$$$fstruct{handle}>   # Doesn't like this at all.

: ...but if I say...

: 	$foo=$$fstruct{handle};
: 	$line=<$foo>;

: Perl's happy, and it does the Right Thing.  But the temporary variable
: is there because of (apparent) syntatic nonsense that I haven't quite
: grokked.  Can anyone explain the correct way to read this
: "$$fstruct{handle}" and why?  Am I missing curlies somewhere?  Help.

The problem is that, as perlop mentions, anything other than a filehandle 
name or a *simple scalar variable* in between angle brackets is taken as a 
glob pattern.  $$fstruct{handle} isn't a simple scalar variable, even 
though it evaluates to a filehandle.

Either do what you did (get the filehandle reference into a simple scalar 
variable), or abandon angle brackets altogether and use 
$fstruct->{handle}->getline().
 


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

Date: Tue, 16 Mar 1999 22:20:34 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Syntax help needed!  References to filehandles and <>.
Message-Id: <1dos4k2.14ty15ig9g3mgN@bay1-411.quincy.ziplink.net>

Clinton Pierce <clintp@geeksalad.org> wrote:

>   $foo=$$fstruct{handle};
>   $line=<$foo>;
> 
> Perl's happy, and it does the Right Thing.  But the temporary variable
> is there because of (apparent) syntatic nonsense that I haven't quite
> grokked.  Can anyone explain the correct way to read this
> "$$fstruct{handle}" and why?  Am I missing curlies somewhere?  Help.

perlop:

    If the string inside the angle brackets is a reference to a scalar
    variable (e.g., <$foo>), then that variable contains the name of the
    filehandle to input from, or a reference to the same.  For example:

        $fh = \*STDIN;
        $line = <$fh>;

    If the string inside angle brackets is not a filehandle or a scalar
    variable containing a filehandle name or reference, then it is
    interpreted as a filename pattern to be globbed, and either a list
    of filenames or the next filename in the list is returned, depending
    on context.  One level of $ interpretation is done first, but you
    can't say <$foo> because that's an indirect filehandle as explained
    in the previous paragraph.  (In older versions of Perl, programmers
    would insert curly brackets to force interpretation as a filename
    glob: <${foo}>. These days, it's considered cleaner to call the
    internal function directly as glob($foo), which is probably the
    right way to have done it in the first place.)


<$$fstruct{handle}> is a filename glob.  Stick with your use of the temp
variable, and you'll be fine.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 16 Mar 1999 22:44:37 -0500
From: mkagalen@lynx02.dac.neu.edu (Michael Kagalenko)
Subject: Unicode/Base64 ?
Message-Id: <7cn8f5$s8h@lynx02.dac.neu.edu>


 Hello,

 I am trying to clean up some mailings that were created by cutting and
 pasting from various sources, incl. WWW. They have strings like
 =92 (which stands for quotation mark). I tried to use MIME::Base64
 and Unicode::String to convert them for printing, but it doesn't
 work;

 use MIME::QuotedPrint;

 $enc='=92';
 $dec = MIME::QuotedPrint::decode($enc);
 print $dec;

Doesn't print anything. Any tips ?

Thanks.



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

Date: Tue, 16 Mar 1999 22:20:35 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Using Select on STDIN ???
Message-Id: <1dos4st.1i41difc4kefN@bay1-411.quincy.ziplink.net>

Greg Forrest <forrestg@uregina.ca> wrote:

> That didn't work. Here is a more detailed listing of my code.

What does "that didn't work" mean?


> my $ClientData = new IO::Select( *\STDIN );

Did you actually try it with that spurious backslash removed?


>         if( $ClientData->can_read($TimeOut) )
>         {
>             my $DataToServer = <STDIN>;

perlfunc:

    WARNING: Do not attempt to mix buffered I/O (like read() or <FH>)
    with select().  You have to use sysread() instead.


> Ronald J Kimball wrote:
> 
> > Greg Forrest <forrestg@uregina.ca> wrote:
> >
> > > my $ClientData = new IO::Select( *\STDIN );
> >
> > No backslash:
> >
> > my $ClientData = new IO::Select( *STDIN );
> >


-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 17 Mar 1999 01:21:34 GMT
From: strads@tmisnet.com (George Crissman)
Subject: Re: Using the print << command
Message-Id: <36ef030d.7437718@news2.tmisnet.com>

On Tue, 16 Mar 1999 07:24:44 GMT, Eric Bohlman <ebohlman@netcom.com>
wrote:

>George Crissman <strads@tmisnet.com> wrote:
>: Yeah, I remember having problems with the print << command.
>
>This is going to sound nitpicky, but it's Not A Good Idea to think in
>terms of the "print << command."  Perl doesn't have one.  Rather, it has
>the print() function, operator, statement, whatever you want to call it, and
>it has the "here-doc" convention for quoting lengthy strings with embedded
>newlines.  The two can certainly be used together, and often are, but
>they're not fundamentally connected; here-doc quoting can be used anywhere
>you can use a literal string, not just as an argument to print().  People 
>often overlook this, which is why I'm being so nitpicky here.

Point taken and appreciated.  Only by being nit-picky can I become
a true Perl programmer.  Thank you.

-- George Crissman
-- strads@tmisnet.com

-----------------------------------------------------------------------
"There is no need to criminalize millions of legitimate and responsible
businesses and individuals in order to stop a very small group of
irresponsible people, particularly when there are other ways already
working ." says Mr. Dan Hufnal of the 10,000 member DEAA 
<http://www.deaa.com>. What does he mean by "already working"?
Maybe:  <http://www.tmisnet.com/~strads/spamhunt/index.html>
-----------------------------------------------------------------------


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

Date: Tue, 16 Mar 1999 22:20:37 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: viewing contents of *.html files
Message-Id: <1dos4xw.19iwg5l1b8u5yoN@bay1-411.quincy.ziplink.net>

Earl Hood <ehood@medusa.acs.uci.edu> wrote:

> In article <1doqheo.4ltgb3rn62rN@bay3-145.quincy.ziplink.net>,
> Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
> >Zenin <zenin@bawdycaste.org> wrote:
> >
> ...
> >>   print "Content-type: text/html\n\n";
> ...
> 
> >Is there anything else we're forgetting?
> 
> Yes.  Using text/plain as the content-type to avoid unneccessary
> work.

Obviously.  But what if this output is going to be embedded in an HTML
document?

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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


------------------------------
End of Perl-Users Digest V8 Issue 5153
**************************************

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