[11803] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5403 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 16 21:07:25 1999

Date: Fri, 16 Apr 99 18:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 16 Apr 1999     Volume: 8 Number: 5403

Today's topics:
        attach a subroutine to a filehandle (Corey Saltiel)
    Re: attach a subroutine to a filehandle <tchrist@mox.perl.com>
        blank form fields <mikej@1185design.com>
    Re: Complex sort help needed. Please! (Tad McClellan)
    Re: DateCalc not working properly (Alastair)
    Re: Help! I can't create an error response from this sc (David Efflandt)
    Re: How to open file across network <tchrist@mox.perl.com>
    Re: like print <<...; load a variable? <tchrist@mox.perl.com>
    Re: like print <<...; load a variable? <cassell@mail.cor.epa.gov>
    Re: Need password HELP!! <gregm@well.com>
    Re: Need password HELP!! (David Efflandt)
        Net::Ping error on win32 perl5.0005_03 palenaka@my-dejanews.com
    Re: New FAQ: How can I read in an entire file all at on (Brand Hilton)
        Opening .Pl Files-Simple question <julia11@my-dejanews.com>
    Re: Opening .Pl Files-Simple question <cassell@mail.cor.epa.gov>
    Re: Reading File to a Scalar? (Tad McClellan)
    Re: reading in dir names into an array. (Earl Hood)
        rename () makes files disappear on Win32 network drive? (Scott Higgins)
        Spell checking CGI inputs on WIN95/NT4 <rpnoble@ibm.net>
    Re: Would anyone care to teach me perl? <gs_london@yahoo.com>
    Re: Writing to syslog on Linux (Alastair)
    Re: { } question/problem (Brand Hilton)
    Re: { } question/problem (Tom Mornini)
    Re: { } question/problem <tchrist@mox.perl.com>
    Re: { } question/problem (David Walford)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 16 Apr 1999 23:07:11 GMT
From: corey@americanrecruitment.com (Corey Saltiel)
Subject: attach a subroutine to a filehandle
Message-Id: <slrn7hfgdt.cr.corey@valis.americanrecruitment.com>


Is it possible to open a filehandle as a pipe ( or alias/reference ...
thingy ) to a subroutine within the same script?  

Am I even making any sense?   (c;


I'm passing a select statement into a pipe attached to a sql*plus
process ( code following ), I want to parse and manipulate
the returned data and will then output this data into some
CGI.  

I don't want to have to open a tempory file to store the 
returned data from the sql query, and then do all the manipulation 
from that temp file - I would prefer to do this in one direct step 
 ... yes, this would definately fall under Laziness.


Something like: 

#!/usr/local/bin/perl

sub query {

   open(SQLPLUS, '|sqlplus arc/arc@webdb') or
      die "Could not open pipe to sql*plus: $!\n";

   print SQLPLUS <<"EOF";

select some_stuff from a_table;

EOF

}

# yeah, this definately does not work -
# but you get the gist right?
#
open(DATA, '|&query');  
while (<DATA>) { #do stuff } 

# and is this as lame as I think it is?
#
*lame = &query
while ($$lame) { #do stuff } 


print("stuff to STDOUT");


__END__


Or something similar...

Or maybe a pointer to some pre-existing text on the matter...

Or even just a reality check and a clue.

<grin>


Beers,

Corey
corey@americanrecruitment.com

---

   "I can say that I don't know what I'm doing, 
    but I can't say I have the time."
       -- The Slackers



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

Date: 16 Apr 1999 17:59:19 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: attach a subroutine to a filehandle
Message-Id: <3717ced7@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, corey@americanrecruitment.com writes:
:Is it possible to open a filehandle as a pipe ( or alias/reference ...
:thingy ) to a subroutine within the same script?  
:
:Am I even making any sense?   (c;

Example 1: 

    #!/usr/bin/perl
    # qnumcat - demo additive output filters

    number();                   # push number filter on STDOUT
    quote();                    # push quote filter on STDOUT

    while (<>) {                # act like /bin/cat
        print;
    } 
    close STDOUT;               # tell kids we're done--politely
    exit;

    sub number {
        my $pid;
        return if $pid = open(STDOUT, "|-");
        die "cannot fork: $!" unless defined $pid;
        while (<STDIN>) { printf "%d: %s", $., $_ } 
        exit;
    } 

    sub quote {
        my $pid;
        return if $pid = open(STDOUT, "|-");
        die "cannot fork: $!" unless defined $pid;
        while (<STDIN>) { print "> $_" } 
        exit;
    } 

Example 2: 

#!/usr/local/bin/perl 
#
# tgent -- retrieve a termcap entry, formatted for
#	   this window size, or the -w width if given
#	   read from /etc/termcap, or -f file, or stdin if isn't_atty
# tchrist@cs.colorado.edu 17/9/93
############################################
# CONFIGURATION SECTION
$DEF_WIDTH = 80;
$DEF_FILE  = '/etc/termcap';
#############################################
main: {
    &parse_args;
    &getwinsz;
    &open_input;
    &run_filter;
    &gen_format;
    &find_entries;
    exit;
}
#############################################
sub usage { 
    die "usage: $0 [-f tcapfile] [-w width] entry ...\n";
}
#############################################
sub parse_args {
    require 'getopts.pl';
    &Getopts("df:w:") || &usage;
    &usage unless @ARGV;
    @wanted{@ARGV} = (1) x @ARGV;
}
#############################################
sub getwinsz {
    $cols = 0;
    if ($opt_w) { 
	$cols = $opt_w; 
	return;
    }
    if (-t STDOUT) {
	($rows, $cols) = split(' ', `stty size`);
	# still might be 0?
    }
    $cols = $DEF_WIDTH  unless $cols;
}
#############################################
sub open_input {
    $FILE = do {
	if    ($opt_f) 	 { $opt_f    }
	elsif (-f STDIN) { "<&STDIN" }
	else 		 { $DEF_FILE }
    };	
    open (FILE) || die "can't open $FILE: $!";
}
#############################################
sub gen_format {
    $cols -= 3;
    $format  = "format STDOUT = \n";
    $format .= '^' . '<' x $cols . "\n";
    $format .= '$entry' . "\n";
    $format .= "\t^" . "<" x ($cols-8) . "~~\n";
    $format .= '$entry' . "\n";
    $format .= ".\n";
    print STDERR $format if $opt_d;
    eval $format; 
    die "bad format:\n$format\n$@" if $@;
    $: = ":";
}
#############################################
sub find_entries {
LINE: while (<FILE>) {
	next LINE if /^#/;
	chop;
	if ( /\\$/ ) { 
	    chop;
	    $_ .= <FILE>; 
	    redo LINE;
	}
	s/:\s*:/:/g;
	$entry = $_;
NAME: for (split(/\|/, (split(/:/,$_,2))[0])) {
	    if ($wanted{$_}) {
		write;
		next LINE;
	    } 
	} # for name
    } # while line
}
#############################################
sub run_filter {
    if ($pid = open(CHILD, "|-")) {
	open(STDOUT, ">&CHILD") || die "can't dup child to stdout: $!";
	$| = 1;
	return;
    }
    die "can't fork: $!"  unless defined $pid;

    $| = 1; $\ = "\n";

    $saveline = '';
    while (<STDIN>) {
	chop;
	s/\s+$//;
	s/^\t([^:])/\t:$1/;
	print /^\S/ ? $saveline : "$saveline\\"  if $saveline;
	$saveline = $_;
    }
    print $saveline if $saveline;
    exit;
}
-- 
"Usenet is like a herd of performing elephants with diarrhea --
massive, difficult to redirect, awe-inspiring, entertaining, and a
source of mind-boggling amounts of excrement when you least expect
it." --gene spafford, 1992


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

Date: Fri, 16 Apr 1999 17:17:00 -0700
From: mikej <mikej@1185design.com>
Subject: blank form fields
Message-Id: <3717D2F3.75F29FA6@1185design.com>

Hi,

I need a way of telling if someone left a form text field blank. I tried
this:

if (defined $survey_form{'comments_need_for_solutions_brochures'}) {
        $solbro_comments = $solbro_comments + 1;
}

but even when I leave that text field blank and submit the form, the
script will see the
defined statement as true and increment the $solbro_comments variable
when its not
supposed to. I only want it to increment $solbro_comments if the text
field had
something entered into it. Any tips?

Thanks....



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

Date: Fri, 16 Apr 1999 19:40:15 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Complex sort help needed. Please!
Message-Id: <voh8f7.h1b.ln@magna.metronet.com>

troutmask338@my-dejanews.com wrote:

: I'm trying to sort lines in a text database based on multiple criteria and am
: having no luck.
[snip]
: What I want to do is sort this list with highest scoring servers listed first
: and sorted by like IP addresses and then alphabetically by server name. 

: so we have the highest-scoring servers at the top, sorted by IP address when
: the score is the same, then sorted alphabetically on the server name.

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

my @unsorted = <DATA>;
chomp @unsorted;

my @sorted =                               # Schwartzian transform
        map { $_->[0] }
        sort { $b->[3] <=> $a->[3]  ||   # numerical, decending (score)
               $a->[2] cmp $b->[2]  ||   # alphabetical, ascending (IP)
               $a->[1] cmp $b->[1]       # alphabetical, ascending (name)
             }
        map {
                [ $_, split ]
        } @unsorted;

foreach (@sorted) {
   print "$_\n";
}

__DATA__
myServer 123.345.567.765 29
yourServer 234.432.234.432 105
hisServer 123.345.567.765 29
herServer 234.432.234.432 105
theirServer 111.222.111.222 13
anotherServer 123.345.567.765 29
yetAnotherServer 255.244.255.244 105
-----------------------------------------


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


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

Date: Fri, 16 Apr 1999 22:52:21 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: DateCalc not working properly
Message-Id: <slrn7hfjaj.5f.alastair@calliope.demon.co.uk>

Ted Timmons <tedder@pacifier.com> wrote:
>But now I've got it installed on a Caldera 1.3 box - that's a Linux
>flavor. First, it didn't install to a path in the @INC - it installed to
>/usr/lib/perl5/site-perl/Date/Calc.pm instead of
>/usr/lib/perl5/site_perl/5.005/i586-linux/Date/Calc.pm. So I put a symlink
>in the latter location for it. Now the "use" line works, and all the
>functions that I call work, but dates_difference doesn't! Why?!

Try ;

Backup (move) the installed modules.
Download the latest version from CPAN (http://www.cpan.org)
Re-build


-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: 17 Apr 1999 00:33:40 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help! I can't create an error response from this script
Message-Id: <slrn7hflkb.h7.efflandt@efflandt.xnet.com>

On Mon, 12 Apr 1999 23:46:59 +0100, Gareth Jones
<gcd_jones@dial.pipex.com> wrote:
>Is there any way of getting this script to display HTML code on an error
>e.g. if the smtp server unavailable, rather than a blank page!
>
>Please Help...

(snip)
>    die $!;

Better to output something useful than die without warning.  Many of us do
not have access to server logs.

You could create an 'error' sub and use that to print a useful html error
message before it exits.  For example if you used &error("Can't open
socket",$!) instead of die $!, you can retrieve passed parameters from @_
in the error sub like:

my ($msg, $err) = @_;

-- 
David Efflandt    efflandt@xnet.com
http://www.xnet.com/~efflandt/


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

Date: 16 Apr 1999 17:51:30 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to open file across network
Message-Id: <3717cd02@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, qinqiang sun <qsun@kitco.ca> writes:
:I tried to open file on another machine by specifying the driver map
:letter and failed. Could you please help me on this? Thank you.

Sure, it's trivial: you merely look at how in C you happen to call the
standard C library function fopen() or the standard system call open(),
and the go and do exactly the same with the Perl open() and sysopen()
calls, respectively.

--tom
-- 
    If I don't document something, it's usually either for a good reason,
    or a bad reason.  In this case it's a good reason.  :-)
            --Larry Wall in <1992Jan17.005405.16806@netlabs.com>


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

Date: 16 Apr 1999 17:24:28 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: like print <<...; load a variable?
Message-Id: <3717c6ac@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    David Cassell <cassell@mail.cor.epa.gov> writes:
:At least a reference to perldata would be nice.  Like the reference
:to the perlop manpage for m// and s/// and tr/// and the generalized
:quotes.

Where?  In perlop?  Perlop has stuff about <<

% man perlop | grep -C '<<'
           left        * / % x
           left        + - .
           left        << >>
           nonassoc    named unary operators
           nonassoc    < > <= >= lt gt le ge
--
       Shift Operators

       Binary "<<" returns the value of its left argument shifted left by the
       number of bits specified by the right argument.  Arguments should be
       integers.  (See also the section on Integer Arithmetic.)
--
       work similarly.  The following are recognized:

           **=    +=    *=    &=    <<=    &&=
                  -=    /=    |=    >>=    ||=
                  .=    %=    ^=
--
               Each regexp tries to match where the previous one leaves off.

                $_ = <<'EOL';
                     $url = new URI::URL "http://www/";   die if $url eq "xXx";
                EOL
--
       Finding the end
            First pass is finding the end of the quoted construct, be it a
            multichar delimiter "\nEOF\n" of <<EOF construct, / which terminates
            qq/ construct, ] which terminates qq[ construct, or > which
            terminates a fileglob started with <.
--
            text.  There are four different cases.

       <<'EOF', m'', s''', tr///, y///
                 No interpolation is performed.

--
       which lasts until the end of that BLOCK.

       The bitwise operators ("&", "|", "^", "~", "<<", and ">>") always produce
       integral results.  (But see also the section on Bitwise String
       Operators.)  However, use integer still has meaning for them.  By
-- 
    "Help save the world!"              --Larry Wall in README


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

Date: Fri, 16 Apr 1999 16:59:27 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: like print <<...; load a variable?
Message-Id: <3717CEDF.BDE681B3@mail.cor.epa.gov>

Tom Christiansen wrote:
> 
>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc,
>     David Cassell <cassell@mail.cor.epa.gov> writes:
> :At least a reference to perldata would be nice.  Like the reference
> :to the perlop manpage for m// and s/// and tr/// and the generalized
> :quotes.
> 
> Where?  In perlop?  Perlop has stuff about <<
> 
> % man perlop | grep -C '<<'
> [snip of text showing that << as a here-doc construct shows up 3 times]

Sorry Tom, I once again failed to make myself clear.

% man perlop | grep 'here-doc'
%

You only get the here-doc info if you already know how to implement it
with '<<'.  My weak suggestion was for a line in perlop looking like
this:

     here-docs
             Here-docs are covered in _perldata_ .

If the user already knows to look for '<<', they'll find the examples
already in perlop.  Otherwise, where do they go?

[A: perlindex, of course.  If it's on their system and they know it's 
there...  Otherwise they're back here again.]

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Fri, 16 Apr 1999 15:10:00 -0700
From: Greg McCann <gregm@well.com>
Subject: Re: Need password HELP!!
Message-Id: <3717B538.348959F0@well.com>

Captain SilverWolf wrote:
> 
> I have been handed a job that is definitely NOT something I have done
> before.  I need to make a page password accessable(sp) only.  I have not
> had to work before and don't really know for sure where to start.   I do
> know that I want it to be a perl cgi script if possible.  More than that,
> as I said, I am not sure of.

One often uses the web server's own access control methods for this (in which
case this would not be a perl question).  Do you have a Very Good Reason for
wanting to do this in Perl?

Greg

-- 

======================
Gregory McCann
http://www.calypteanna.com

"Be kind, for everyone you meet is fighting a great battle."  Saint Philo of
Alexandria


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

Date: 17 Apr 1999 01:01:20 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Need password HELP!!
Message-Id: <slrn7hfn89.h7.efflandt@efflandt.xnet.com>

On 16 Apr 1999 21:26:13 GMT, Captain SilverWolf <starwolf@rahul.net> wrote:
>I have been handed a job that is definitely NOT something I have done
>before.  I need to make a page password accessable(sp) only.  I have not
>had to work before and don't really know for sure where to start.   I do
>know that I want it to be a perl cgi script if possible.  More than that,
>as I said, I am not sure of.

It depends upon what you are trying to protect.  See webserver docs (and
appropriate newsgroup) to password protect a directory or selective files.
If you do want to do it with a perl script for something like an admin
function of something that is otherwise publically accessible, it is best
to crypt the password.  See my htpasswd.cgi script for some clues at:
http://www.xnet.com/~efflandt/pub/

>Please note that I am not posting from my usual account, so if you want
>(or need) to reach me directly, my correct email addy is:
>sarahj@earthling.net.
>
>TIA
>
>	SJS posting from a friend's account.

-- 
David Efflandt    efflandt@xnet.com
http://www.xnet.com/~efflandt/


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

Date: Sat, 17 Apr 1999 00:22:07 GMT
From: palenaka@my-dejanews.com
Subject: Net::Ping error on win32 perl5.0005_03
Message-Id: <7f8k79$s8r$1@nnrp1.dejanews.com>

I am trying to implement a ping program in perl (win32) using the Net::Ping
module.
The program reads a file that contains one IP address per line and checks it
for reachability.

This is the error code I am getting: Can't load
'C:\PERL\5.00503\lib/MSWin32-x86/auto/IO/IO.dll' for module IO: load_
file:The system could not find the environment option that was entered at
C:\PERL\5.00503\lib/MSWin32-x86/DynaLoader.pm line 16 9.  at
C:\PERL\5.00503\lib/MSWin32-x86/IO/Handle.pm line 248 BEGIN
failed--compilation aborted at C:\PERL\5.00503\lib/MSWin32-x86/IO/Seekable
 .pm line 50. BEGIN failed--compilation aborted at
C:\PERL\5.00503\lib/MSWin32-x86/IO/File.pm line 111. BEGIN
failed--compilation aborted at C:\PERL\5.00503\lib/Net/Ping.pm line 19. BEGIN
failed--compilation aborted at sweep.pl line 4.

Here is the program source:
use Net::Ping;
open(FILE, "./newlist");
@iplist = <FILE>;
close(FILE);
chop(@iplist);
foreach (@iplist) {
	$p = Net::Ping->new("icmp");
	print "$_ is ";
	print "NOT " unless $p->ping($_, 2);
	print "responding, Jimmy!\n";
	sleep(1);
}
$p->close();

Platform Specifics: Summary of my perl5 (5.0 patchlevel 5 subversion 03)
configuration:	Platform:  osname=MSWin32, osvers=4.0, archname=MSWin32-x86 
uname=''  hint=recommended, useposix=true, d_sigaction=undef 
usethreads=undef useperlio=undef d_sfio=undef  Compiler:  cc='gcc',
optimize='-g -O2 ', gccversion=  cppflags='-DWIN32'  ccflags ='-g -O2 
-DWIN32  '  stdchar='char', d_stdstdio=undef, usevfork=false  intsize=4,
longsize=4, ptrsize=4, doublesize=8  d_longlong=undef, longlongsize=8,
d_longdbl=define, longdblsize=12  alignbytes=8, usemymalloc=n,
prototype=define  Linker and Libraries:  ld='gcc', ldflags ='
-L"C:\mingw32\lib"'  libpth=C:\mingw32\lib  libs= -ladvapi32 -luser32
-lnetapi32 -lwsock32 -lmingw32 -lgcc -lmoldname -l crtdll -lkernel32 
libc=-lcrtdll, so=dll, useshrplib=yes, libperl=libperl.a  Dynamic Linking: 
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '  cccdlflags=' ',
lddlflags='-mdll  -L"C:\mingw32\lib"' Characteristics of this binary (from
libperl):  Compile-time options: MULTIPLICITY  Built under MSWin32  Compiled
at Apr 16 1999 18:06:35  %ENV:	PERL_BADLANG=""1""  @INC: 
C:\PERL\5.00503\lib/MSWin32-x86  C:\PERL\5.00503\lib 
C:\PERL\site\5.00503\lib  .

Perl was compiled with no errors with mingw32 gcc 2.91.60 on win98 machine
running 4NT shell. This is the same machine I am running my test program from.
The script works fine under UNIX.


Any help would be appreciated

Thanks in advace,
Brent



-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 16 Apr 1999 22:29:04 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: New FAQ: How can I read in an entire file all at once?
Message-Id: <7f8djg$9p22@mercury.adc.com>

In article <37179cf0@cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:

>which allow you to tie an arrya to a file so that accessing an element
                              ^^

-- 
 _____ 
|///  |   Brand Hilton  bhilton@adc.com
|  ADC|   ADC Telecommunications, ATM Transport Division
|_____|   Richardson, Texas


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

Date: Fri, 16 Apr 1999 22:58:31 GMT
From: Nat <julia11@my-dejanews.com>
Subject: Opening .Pl Files-Simple question
Message-Id: <7f8faj$o2u$1@nnrp1.dejanews.com>

Hi, please help, this is a simple question, how do I open .pl files? I can't
use notepad or simpletext because they are too big, I am trying to install a
shopping cart. If I use an html editor it crashes my system, any ideas? email
me at sthenri@ntr.ne

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 16 Apr 1999 16:47:55 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Opening .Pl Files-Simple question
Message-Id: <3717CC2B.FBADEEF0@mail.cor.epa.gov>

Nat wrote:
> 
> Hi, please help, this is a simple question, how do I open .pl files? I can't
> use notepad or simpletext because they are too big,

Have you tried WordPad?  If you don't like that, there are a hundred 
freeware text|file|programming editors on the web that you could use.
But that's not a Perl question.  You really shouldn't ask *application*
questions here.  It's not considered polite.

And if you're asking (1) how to use the right mouse button to get the
"Open With" menu; or (2) how to associate a file type; well then that's
REALLY not a question for this newsgroup.

>                                                     I am trying to install a
> shopping cart.

Hmmm.  That doesn't bode well.  Lately there have been a slew of 'the
shopping cart program I downloaded is broken, please fix it' requests
here.  So let me give you some pre-installation advice.  If it doesn't
install, or it doesn't work, go back to the author and ask him/her/it
and ask for help.

>                If I use an html editor it crashes my system, any ideas?

My first idea is that you should look into other html editors.  Perl
programs ending in .pl are just text.  But don't use your html editor
to fiddle the Perl program, just in case.

>                                                                         email
> me at sthenri@ntr.ne

I would, except that it is very inconvenient to do so using the news-
reader I'm stuck with at the moment.  Nat - or Julia - what's wrong
with your From: address in your header?

Besides, in Usenet it is considered impolite to implicitly say that
you can't be bothered to read the newsgroup in which you posted a
request for help.

-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Fri, 16 Apr 1999 17:37:05 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading File to a Scalar?
Message-Id: <1ia8f7.5ra.ln@magna.metronet.com>

Ray A. Lopez (rdsys@inficad.com) wrote:
: I wanted to know if there were any other (or better) ways of reading
: file data into a scalar?  


   There are better ways.


: Below is one implementation I came up with.
: Any other ways????


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

: my $slurp;

: open (FILE, "< file") or die "Can not open file!\n";

: while (<FILE>) {
:    $slurp = join ('',  $slurp, $_);
: }


   Replace the 3 lines above with:

      undef $/;         # enable slurp mode
      $slurp = <FILE>;  # do the slurping


   or at least with this:

      $slurp = join('', <FILE>);


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


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

Date: 17 Apr 1999 00:10:33 GMT
From: ehood@geneva.acs.uci.edu (Earl Hood)
Subject: Re: reading in dir names into an array.
Message-Id: <7f8jhp$as2@news.service.uci.edu>

In article <37161CCB.760E121E@harris.com>, George  <dscapin@harris.com> wrote:
>I was using the command @array = <*.jpg> to read all jpg files in the
>current directory into the array.  This worked fine until I put the
>program on a server (NT).  I was developing on win98.  How come this
>command won't work on the NT server?  What is another way of doing
>this.  Thank you.

Look into the opendir, readdir, and closedir operators.  Also
check out the grep operator since it can be used to help extract
specific filenames via regex.

	--ewh
-- 
             Earl Hood              | University of California: Irvine
      ehood@medusa.acs.uci.edu      |      Electronic Loiterer
http://www.oac.uci.edu/indiv/ehood/ | Dabbler of SGML/WWW/Perl/MIME


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

Date: Fri, 16 Apr 1999 23:51:15 GMT
From: xyzscott_higgins@ccgate.apl.comxyz (Scott Higgins)
Subject: rename () makes files disappear on Win32 network drive?
Message-Id: <3717cb5d.354453817@news.newsguy.com>

I am trying to change a bunch of files from uppercase to lowercase.
Using the rename function on my local workstation on both an NTFS
drive and a FAT partition produce the expected rename results.
However, when I run the script on a network drive, the files disappear
(and the server just crashed, but I won't say anything if you don't).
I use the cop-out system ("rename $oldname $newname"); and it works
fine.

Here's a script that I stole shamelessly from dejanews:

by Andrew Fry


use strict;

use File::Find;



my $newname;

my $fullname;

my @DIRLIST;


@ARGV = '.' unless @ARGV;

@DIRLIST = @ARGV;

find(\&renamedf,@DIRLIST);



sub renamedf {

  $fullname = $File::Find::name;
  
  # does name contain any uppercase character ?
  
  if ($_ =~ /[A-Z]/)
  
  {
    
    $newname = $_;
    
    $newname =~ tr/A-Z/a-z/;
    
    if (-f $_)
    
    {
      
    print "File $fullname: renaming as $newname\n";
    rename($_,$newname);
    
    }
    
    if (-d $_)
    
    {
      
      print "Directory $fullname: renaming as $newname\n";
      rename($_,$newname);
    
    }
  
  }

}


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

Date: Fri, 16 Apr 1999 18:48:37 -0400
From: Richard Noble <rpnoble@ibm.net>
Subject: Spell checking CGI inputs on WIN95/NT4
Message-Id: <3717BE45.88D634FC@ibm.net>

Does anyone have any idea how to spell check a users input from a cgi
form? I own VisualSpeller which is a OCX control for VB. Can Win32 OLE
provide me access to this? If not can I link to any of the functions in
WORD97?

Thanks for your input.....
Richard Noble



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

Date: Sat, 17 Apr 1999 01:28:05 +0100
From: "ggs" <gs_london@yahoo.com>
Subject: Re: Would anyone care to teach me perl?
Message-Id: <7f8kdl$89s$1@starburst.uk.insnet.net>

Lesson One

-------start------
#!/usr/bin/perl
------end-------
put the above in a file and save it. (filename= lesson_one.pl)

come back next month for Lesson Two (or buy a book)

Raymond Yu wrote in message <371513C8.3CD3086C@nettaxi.com>...
>Would anyone care to teach me perl?  Just with email though.
>




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

Date: Fri, 16 Apr 1999 23:08:07 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Writing to syslog on Linux
Message-Id: <slrn7hfk84.5f.alastair@calliope.demon.co.uk>

Thriveni Bhakta <thriveni@prodigy.net> wrote:
>    I have not been abel to write to syslog using Perl on Linux.
>
>    Is this a known problem ?

No.

>    Any suggestions/solutions ?

What doesn't work?

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: 16 Apr 1999 22:03:42 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: { } question/problem
Message-Id: <7f8c3u$9p21@mercury.adc.com>

In article <7f8aa3$iok$1@murrow.corp.sgi.com>,
David Walford <davewal@echo.corp.sgi.com> wrote:
>
>I am not sure the information below is helping me or maybe I am not
>understanding how it is applied.
>
>I am not trying to assign a variable with a variable.
>I have a bunch of arrays with titles like "name_array, date_array, time_array".
>I would like to use a variable to define the first part of the arrays title for
>a subroutine to use the appropriate array.
>
>This was my example:
>for (sort keys %${tag}_array )  <-- But this doesn't work.

First off, since you're trying to use "keys", I'm guessing that you
don't really have arrays.  You have hashes.

The following segment of the FAQ Tom posted is particularly relevant
to your question:

>|> Another reason that folks sometimes think they want a variable to contain
>|> the name of a variable is because they don't know how to build proper
>|> data structures using hashes.  For example, let's say they wanted two
>|> hashes in their program: %fred and %barney, and to use another scalar
>|> variable to refer to those by name.
>|> 
>|>     $name = "fred";
>|>     $$name{WIFE} = "wilma";     # set %fred
>|> 
>|>     $name = "barney";           
>|>     $$name{WIFE} = "betty";	# set %barney
>|> 
>|> This is still a symbolic reference, and is still saddled with the
>|> problems enumerated above.  It would be far better to write:
>|> 
>|>     $folks{"fred"}{WIFE}   = "wilma";
>|>     $folks{"barney"}{WIFE} = "betty";
>|> 
>|> And just use a multilevel hash to start with.

Applying this to your particular problem, you need a multilevel hash
such that your for loop looks like this:


  for (sort keys %{$arrays{$tag}})

For more info about multilevel hashes, read perldsc or perllol.

-- 
 _____ 
|///  |   Brand Hilton  bhilton@adc.com
|  ADC|   ADC Telecommunications, ATM Transport Division
|_____|   Richardson, Texas


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

Date: Fri, 16 Apr 1999 22:54:13 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: { } question/problem
Message-Id: <tmorniniFAB0yD.M2v@netcom.com>

David Walford (davewal@echo.corp.sgi.com) wrote:

: I am not trying to assign a variable with a variable.
: I have a bunch of arrays with titles like "name_array, date_array, time_
: I would like to use a variable to define the first part of the arrays ti
: a subroutine to use the appropriate array.

: This was my example:
: for (sort keys %${tag}_array )  <-- But this doesn't work.

Assuming you have:
#!/usr/bin/perl -w

use strict;
no strict 'refs';

my @name_array=qw(a bunch of names in here);
my @date_array=qw(a bunch of dates in here);
my @time_array=qw(a bunch of times in here);

{
 local $,=' ';

 print @name_array,"\n";
 print @date_array,"\n";
 print @time_array,"\n";

 for my $array (qw(name date time)) {
  push @{"${array}_array"},"Hello There";
  print "${array}_array=";
  print @{"${array}_array"},"\n";
 }
}

Which will add "Hello There" as a single element to each array then
print each array.

This uses soft references, which requires the no strict 'refs' line.

This is not giving me the output I'd expect, though, but I don't have
any time to debug it right now! Hope this helps.

Why does this program output this (aside from the fact that it is correct)?

a bunch of names in here 
a bunch of dates in here 
a bunch of times in here 
name_array=Hello There 
date_array=Hello There 
time_array=Hello There 

I expected:

a bunch of names in here 
a bunch of dates in here 
a bunch of times in here 
name_array=a bunch of names in here Hello There 
date_array=a bunch of dates in here Hello There 
time_array=a bunch of times in here Hello There 

:-( Just when I thought I was getting all this stuff!

-- Tom Mornini
-- InfoMania


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

Date: 16 Apr 1999 17:39:53 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: { } question/problem
Message-Id: <3717ca49@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    davewal@echo.corp.sgi.com (David Walford) writes:
:for (sort keys %${tag}_array )  <-- But this doesn't work.

You're doing the wrong thing.  Do not use variables to hold
names of variables.  Learn multilevel data structures.  This
isn't perl1, you know.

--tom
-- 
    > This made me wonder, suddenly: can telnet be written in perl?
    Of course it can be written in Perl.  Now if you'd said nroff, 
    that would be more challenging...   --Larry Wall


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

Date: 17 Apr 1999 00:00:33 GMT
From: davewal@echo.corp.sgi.com (David Walford)
Subject: Re: { } question/problem
Message-Id: <7f8iv1$m9s$1@murrow.corp.sgi.com>

I got it working with the multi-dimensional hash.
Thanks Tom C. and Brand Hilton.

Thanks
David


In article <3717ca49@cs.colorado.edu>, Tom Christiansen <tchrist@mox.perl.com>
writes:
|>  [courtesy cc of this posting sent to cited author via email]
|> 
|> In comp.lang.perl.misc, 
|>     davewal@echo.corp.sgi.com (David Walford) writes:
|> :for (sort keys %${tag}_array )  <-- But this doesn't work.
|> 
|> You're doing the wrong thing.  Do not use variables to hold
|> names of variables.  Learn multilevel data structures.  This
|> isn't perl1, you know.
|> 
|> --tom
|> -- 
|>     > This made me wonder, suddenly: can telnet be written in perl?
|>     Of course it can be written in Perl.  Now if you'd said nroff, 
|>     that would be more challenging...   --Larry Wall

-- 
--------------------------------------------------------------
 David M. Walford           | email: davewal@corp.sgi.com
 RealityCenter Tech. Engr.  | m/s: 06U-122 
 Silicon Graphics, Inc.     | voice: 650-933-6451 
 Corporate Briefing Center  | fax: 650-932-6451 


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

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

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