[22043] in Perl-Users-Digest
Perl-Users Digest, Issue: 4265 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 15 06:05:37 2002
Date: Sun, 15 Dec 2002 03:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 15 Dec 2002 Volume: 10 Number: 4265
Today's topics:
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: escape special chars before loading into MySQL <goldbb2@earthlink.net>
Help with Assignment of Split Value from STDIN to Hash Joe Blow
Re: Help with Assignment of Split Value from STDIN to H <tassilo.parseval@post.rwth-aachen.de>
Re: Help with Assignment of Split Value from STDIN to H <palladium#@spinn.net>
Re: HTTP::Headers <mbudash@sonic.net>
Need help with Script <autochem@worldnet.att.net>
Re: Need help with Script Rod
Re: Need help with Script <jurgenex@hotmail.com>
Re: Odd pack() behavior <bart.lateur@pandora.be>
Re: Sorting large hex numbers <goldbb2@earthlink.net>
STDIN/stream/filehandle<?> question <66@bowser.stanford.edu>
Re: Syntax of subroutine declarations, relating to use <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Re: Test::More and overloading "==" <bart.lateur@pandora.be>
Re: win2k total directory size, going down one level at <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Dec 2002 09:15:15 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1039943659@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
XEmacs port is bundled in XEmacs setup.exe available from
XEmacs site.
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
<ilya@math.ohio-state.edu> Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr@ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Sun, 15 Dec 2002 00:22:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: escape special chars before loading into MySQL
Message-Id: <3DFC11AA.5D3F4A04@earthlink.net>
user wrote:
[snip]
> $mysql_dbh->do("INSERT INTO $table (content,filename,filesize) VALUES
> ('$content', '$upload_name','$upload_size')");
$mysql_dbh->do( qq[
INSERT INTO $table
(content, filename, filesize) VALUES (?, ?, ?)
], undef, $content, $upload_name, $upload_size );
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sun, 15 Dec 2002 00:51:31 -0800
From: Joe Blow
Subject: Help with Assignment of Split Value from STDIN to Hash Values (As Arrays)
Message-Id: <3icovuc92n8jqaeb90929uuaoai2l4or3k@4ax.com>
Hello,
First off, I hope I named the subject correctly, feel free to beat me
senseless if not.
I seem to be close to solving this one. But My split value is getting
assigned to the wrong variable. Any Help would Be Appreciated.
I have an external Program that STDOUT's a list of configuration items
/home/rod/>getconfig -c
ITEM1 123456
ITEM2 654321
ITEM3 162534
I am calling this with Backticks
I have a clean array subroutine, that chomps lines, and removes
whitespace (This Seems to Work As Expected)
I am attempting this .
Take the stdout of getconfig application
while reading in the lines, chomp all newline characters,
remove all whitespace except for space between
ITEM1 and 123456, split that value and
assign to $config->{items}->names (as Array element) and
$config->{items}->{values} (as Array element).
When I run this now, all values after being split are being assigned
to $config->{items}->{values}. They are cleaned as requested, I am
just confused as why this doesn't assign the first split scalar to
$config->{items}->{names}.
Complete Sample Snippet Below:
Thank You,
Rod
#!/usr/local/perl/bin/perl -w
#Snippet for Perl Gods to Help
use strict;
use Data::Dumper;
my $seperator="--------------------------------------------------\n";
#Sample Data with Variable whitespace to Simulate getconfig -c output
(Single Item Only Real World is multiline)
my $SampleData="DEPOTS 148130767.1.580 \n";
#Show Unclean Data
print Dumper($SampleData);
#Verify clean_array works
my @CleanData=clean_array($SampleData);
#Show Cleaned Data
print $seperator;
print Dumper(@CleanData);
my $config=undef;
$config->{loadtime}=time;
###BEGIN PROBLEM CODE
clean_array(@{$config->{items}->{names}},
@{$config->{items}->{values}} = split("
",$SampleData));
###END PROBLEM CODE
$config->{endtime}=time;
print $seperator;
print Dumper($config);
sub clean_array{
chomp(@_);
foreach (@_){
#Remove WhiteSpace At Beginning of Line
s/^\s+//;
#Remove WhiteSpace At End of Line
s/\s+$//;
#Replace Multiple Spaces with Single Space
s/\s+/ /;
};
return @_;
};
OUTPUT of snip.pl
>perl -w snip.pl
$VAR1 = 'DEPOTS 148130767.1.580
';
--------------------------------------------------
$VAR1 = 'DEPOTS 148130767.1.580';
--------------------------------------------------
$VAR1 = {
'items' => {
'values' => [
'DEPOTS',
'148130767.1.580'
],
'names' => []
},
'endtime' => 1039942214,
'loadtime' => 1039942214
};
>Exit code: 0
------------------------------
Date: 15 Dec 2002 08:41:51 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Help with Assignment of Split Value from STDIN to Hash Values (As Arrays)
Message-Id: <athf8f$scn$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Joe Blow:
> Hello,
> First off, I hope I named the subject correctly, feel free to beat me
> senseless if not.
Your attempt to come up with a descriptive subject-line sure is
appreciated. ;-) Your problem is partly about split(), but mostly about
assigning to lists and using a slightly inappropriate data-structure.
See below.
> I seem to be close to solving this one. But My split value is getting
> assigned to the wrong variable. Any Help would Be Appreciated.
>
> I have an external Program that STDOUT's a list of configuration items
> /home/rod/>getconfig -c
> ITEM1 123456
> ITEM2 654321
> ITEM3 162534
>
> I am calling this with Backticks
>
> I have a clean array subroutine, that chomps lines, and removes
> whitespace (This Seems to Work As Expected)
>
> I am attempting this .
> Take the stdout of getconfig application
> while reading in the lines, chomp all newline characters,
> remove all whitespace except for space between
> ITEM1 and 123456, split that value and
> assign to $config->{items}->names (as Array element) and
> $config->{items}->{values} (as Array element).
>
> When I run this now, all values after being split are being assigned
> to $config->{items}->{values}. They are cleaned as requested, I am
> just confused as why this doesn't assign the first split scalar to
> $config->{items}->{names}.
[...]
The code in question was:
clean_array(@{$config->{items}->{names}},
@{$config->{items}->{values}} = split(" ", $SampleData));
Let's move that out of the function-call:
@{ $config->{items}->{names} }, @{ $config->{items}->{values} } =
split (" ", $SampleData);
There are two (counting the first argument to split three) problems in
the above code. First of all: Do you know how Perl parses that? It is
actually:
@{ $config->{items}->{names} },
( @{ $config->{items}->{values} } = split (" ", $SampleData) );
Basically you have two statements, separated by a comma. An array in void
context (that's a no-op in this context) and an array which you assign
the result of split to. That's the explanation why the records all end
up in $config->{items}->{values}. If you want to have a list on the
left-hand side, put parens around it:
(@{ $config->{items}->{names} }, @{ $config->{items}->{values} }) =
split ...;
But this wont solve your problem here because now all records will end
up in $config->{items}->{names} instead. That's because the first
array in the list will gobble up all the records as returned by split().
You can solve that by telling Perl how many arguments it should put into
each array. Use an array-slice for that:
( @{ $c->{i}->{names} }[0], @{ $c->{i}->{values} }[0] ) =
split(" ", $SampleData);
Still, this has some disadvantages. It will only work for the first
time...since it always assigns to the first element of these two arrays
(array-subscript 0). If you do it a second time, the previous values
will be replaced with the new ones.
In this situation, splitting the whole thing into two statements is
easier and also clearer. First split() by assigning to some temporary
variables and then push() these variables to the respective arrays:
my ($name, $val) = split / /, $SampleData;
push @{ $config->{items}->{names} }, $name;
push @{ $config->{items}->{values} }, $val;
Here, I also changed the first argument to split from " " to / /.
Remember that this first argument is a regular expression and not a
string. Even if you pass a string, this string will get interpreted as a
regular expression. This can make quite a difference when passing "." as
argument or so. It has to be /\./ (or "\." if you insist to use quotes,
but don't do that).
But why do you insist on using two arrays (one conspicuously called
'values') when a hash would be much more appropriate here? 'names'
become the keys. The code would then look like:
%{ $config->{items} } = split / /, $SampleData;
^
a hash!
You can now store the data in the items key.
The only problem with this approach is when names can in fact show up
multiple times. If that is not the case, you can skip the rest of the
posting. If it is read on. The idea is to associate an array-reference
with each key in $config->{items}:
my ($name, $val) = split / /, $SampleData;
push @{ $config->{items}->{ $name } }, $val;
Now you always have an array-reference associated with each name in your
hash so that you can store an arbitrary number of values in it.
A dump of this would result in:
$VAR1 = {
'items' => {
'DEPOTS' => [
'148130767.1.580'
]
},
'endtime' => 1039942214,
'loadtime' => 1039942214
};
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Sun, 15 Dec 2002 09:31:50 -0000
From: Rod <palladium#@spinn.net>
Subject: Re: Help with Assignment of Split Value from STDIN to Hash Values (As Arrays)
Message-Id: <Xns92E51A0C5680Fpalladiumspinnnet@216.168.3.44>
"Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in
news:athf8f$scn$1@nets3.rz.RWTH-Aachen.DE:
> Also sprach Joe Blow:
Sprached.
>
> Your attempt to come up with a descriptive subject-line sure is
> appreciated. ;-) Your problem is partly about split(), but mostly
> about assigning to lists and using a slightly inappropriate
> data-structure. See below.
Thanks for being gentle..
>
>
> my ($name, $val) = split / /, $SampleData;
> push @{ $config->{items}->{names} }, $name;
> push @{ $config->{items}->{values} }, $val;
>
I had multiple lines initially, but was attempting to "clean" them
all at the same time. This is much more readable, and would do what I want.
I was trying to keep from reading in and sending each line through my
cleaner. (I guess it does anyway though).
> Here, I also changed the first argument to split from " " to / /.
> Remember that this first argument is a regular expression and not a
> string. Even if you pass a string, this string will get interpreted as
> a regular expression. This can make quite a difference when passing
> "." as argument or so. It has to be /\./ (or "\." if you insist to use
> quotes, but don't do that).
Thanks for the clarity.
>
> But why do you insist on using two arrays (one conspicuously called
> 'values') when a hash would be much more appropriate here? 'names'
> become the keys. The code would then look like:
>
> %{ $config->{items} } = split / /, $SampleData;
> ^
> a hash!
This is how I was doing it initially (Not quite as elegantly though).
I found it easier though to enumerate the lists, manage some
presorting with an array. But your way is faster, and more manageable /
flexible.
my original $config is actually brought in from XML::Simple;
Then I append to the configs the values from the getconfig application
Finally I use all of that data junk to fix a bunch of machines remotely.
Thanks again for the advice I changed my code to reflect this.
Rodney
Code Change Below
if (-e $config->{executable}->{config}){
my @temp=`$config->{executable}->{config} $config->{executable}->
{flags}`;
foreach (@temp){
$_=clean($_);
my ($name, $val) = split / /, $_;
$config->{items}->{ $name }=$val;
};
} else {
logger(0,"Configuration Executable Not Found - Exiting Gracefully");
&exithndlr(255);
};
and added a "clean" subroutine to just clean for a single scalar
sub clean{
chomp($_);
$_=~s/^\s+//;
$_=~s/\s+$//;
$_=~s/\s+/ /g;
return $_;
};
------------------------------
Date: Sun, 15 Dec 2002 05:55:30 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: HTTP::Headers
Message-Id: <mbudash-F65540.21552914122002@typhoon.sonic.net>
In article <uvo2dl2362st46@corp.supernews.com>,
Timothy Butler <tbutler@uninetsolutions.com> wrote:
> > it might be if you were *passed* an HTTP::Header object, but you're not
> > in a cgi environment...
>
> Hmm... would it make a difference if mod_perl was running, I guess? Any
> ideas on how might I circumvent that?
beyond my expertise... anybody else?
> >> Once I got that working through this method, I figured I
> >> might have a chance at getting what I *really* wanted:
> >> authorization_basic
> >
> > once again, if cgi, the HTTP_REMOTE_USER environment variable will
> > contain the value of the user authorized via basic authentication, if
> > any. the password cannot be gotten this way (for obvious security
> > reasons)
>
> Well HTTP_REMOTE_USER does return the user, but also need the password...
> that's where the trouble begins. What I need seems to be the
> "HTTP_AUTHORIZE" field, which incidentally is empty. I know php receives
> this information, so I'm just trying to figure out how to get it in Perl.
you can't.
------------------------------
Date: Sun, 15 Dec 2002 06:57:40 GMT
From: "Way of the Kali" <autochem@worldnet.att.net>
Subject: Need help with Script
Message-Id: <EJVK9.62733$hK4.5180688@bgtnsc05-news.ops.worldnet.att.net>
I have this script for a voting poll and Im getting an error that says "Vote
area x is not valid in this poll
Can somebody help me determine what was causing that error message?
Below is part of the script:
TIA
if($ENV{'CONTENT_LENGTH'}) { Variables();
if(Valid_Vote()) {
if(IP_Check()) { Add_Hit(); HTML_Output(); }
else { HTML_Error(\$voted); } }
else { HTML_Error(\$missing); } }
elsif($ENV{'QUERY_STRING'}) { Variables(); HTML_Output(); }
else { Error(0,\'No data was found',\$ENV{'HTTP_REFERER'}); }
sub Variables { my($info,$key,$value);
($ENV{'CONTENT_LENGTH'})?read(STDIN,$info,$ENV{'CONTENT_LENGTH'}):($info=$EN
V{'QUERY_STRING'});
foreach my $item (split(/&/,$info)) { ($key,$value)=split(/=/,$item,2);
$value=~tr/+/ /; $value=~s/%([A-F0-9]{2})/pack('C',hex($1))/ge;
$form{$key}=$value; } if($form{'Poll'}) { $log=$logdir.$form{'Poll'}.'.log';
open(VOTES,"< $log") or Error(1,\'$logdir + Poll Name + .log',\$log);
flock(VOTES,1); @vote=split(/\|/,<VOTES>); flock(VOTES,8); close(VOTES); }
else { Error(0,\'No log file was specified in the
HTML',\$ENV{'HTTP_REFERER'}); } }
sub Valid_Vote { Error(0,\"Vote area <b>$form{'Vote'}</b> is not valid in
this poll ($form{'Poll'})",\$log)
------------------------------
Date: Sun, 15 Dec 2002 01:15:16 -0800
From: Rod
Subject: Re: Need help with Script
Message-Id: <gnhovuoecou9iakqvh6cfqcdmgca36h0dp@4ax.com>
On Sun, 15 Dec 2002 06:57:40 GMT, "Way of the Kali"
<autochem@worldnet.att.net> wrote:
>I have this script for a voting poll and Im getting an error that says "Vote
>area x is not valid in this poll
>
>Can somebody help me determine what was causing that error message?
>
>Below is part of the script:
>
>TIA
Other than the visible errors?
It would seem that subroutine Valid_Vote Gets Called and
$form('Vote') = x
Realistically this is a very poorly written attempt at CGI programming
in perl. I suggest reading >> perldoc CGI
and then scrapping this attempt and rewriting properly.
Rodney
------------------------------
Date: Sun, 15 Dec 2002 09:16:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Need help with Script
Message-Id: <RLXK9.14791$4W1.12597@nwrddc02.gnilink.net>
Way of the Kali wrote:
> I have this script for a voting poll and Im getting an error that
> says "Vote area x is not valid in this poll
Well, it is not a Perl error message. It must come from somewhere else.
> Can somebody help me determine what was causing that error message?
May I suggest to add strictures and warnings first.
Then run the program through a Perl beautifier.
And then it may be possible to analyse the logic and structure of the
program.
In the current format it is asking a bit much to even look at the code.
Oh, and you may want to reduce your program to a minimalistic version that
still exposes the problem. Your current snippet doesn't even compile:
Missing right curly or square bracket at C:\tmp\t.pl line 18, at end of line
syntax error at C:\tmp\t.pl line 18, at EOF
Execution of C:\tmp\t.pl aborted due to compilation errors.
> Below is part of the script:
[badly formatted code snipped]
jue
------------------------------
Date: Sun, 15 Dec 2002 10:24:07 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Odd pack() behavior
Message-Id: <fplovu0r2u1b3ia5gtt8jl6fale1g2fofe@4ax.com>
Brian C. Lane wrote:
>I've run into a strange problem with pack. It seems to be outputting a
>single byte for 'H2' on one machine, which is the correct behavior. But on
>another maching I'm getting 2 bytes, and they aren't what they are supposed
>to be.
Hmm... Some automatic stealthed conversion to UTF-8? Are the bytes
"\xC3\xBF"?
--
Bart.
------------------------------
Date: Sun, 15 Dec 2002 00:20:04 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting large hex numbers
Message-Id: <3DFC1104.2D10B50E@earthlink.net>
tim wrote:
>
> Is there a module or method of handling large hex numbers? I want to
> sort them into largest first order, it works fine for number of 8
> characters or below, but anything above I get error messages:
> Hexadecimal number > 0xffffffff non-portable at test.pl line 3.
> Integer overflow in hexadecimal number at test 3.
>
> #!/usr/bin/perl -w
> @array=("3E1D302EDFDFDFDF", "3E1D", "4E1D302ECCCC6666",
> "4E1D302ECCCC6667","4E1D302DCCCC6666", "3E");
> my @array= sort { hex($b) <=> hex($a) } @array;
> foreach (@array) {
> print "$_\n";
> }
>
> p.s. I sent this to the wrong groups first, so apollogies for
> multi-posting!
Try this:
#!/usr/bin/perl -w
use strict;
print $_, "\n" for sort {
length($a) <=> length($b) or $a cmp $b
} qw(3E1D302EDFDFDFDF 3E1D 4E1D302ECCCC6666
4E1D302ECCCC6667 4E1D302DCCCC6666 3E);
__END__
Assuming that there are no leading zeros, shorter hex numbers are of
course numerically smaller than longer hex numbers. For equal length
hex numbers, a lexigraphical comparison works fine.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sun, 15 Dec 2002 00:51:17 -0800
From: Jonathan Dugan <66@bowser.stanford.edu>
Subject: STDIN/stream/filehandle<?> question
Message-Id: <lifovu4cc49lpvo55bn3a94qq1kvkdfv4l@4ax.com>
This has been a problem for me in the past, and now I am writing
something that really makes me want to solve it.
I want to have a perl script that accepts data from STDIN, but then
also accepts non-blocking user-input characters at cetain times while
it's ruunning. I want to write script2 so that I can do
script1.pl | script2.pl | script3.pl
or
cat datafile | script2.pl | script3.pl
and while running, have script2 present an interface to the user and
the the user can input characters, have term::readline input, etc.,
then the user selects "go" and have it save or spit out data, or
whatever.
THE PROBLEM:
I can't seem to get anything to read correctly from STDIN once I have
the script reading from STDIN already.
I've tried 3 different ways:
1 POSIX::getchar()
2 TermReadKey (see
http://search.cpan.org/author/JSTOWE/TermReadKey-2.21/ReadKey.pm)
3 and this little snippet from the web that I've used before:
sub GetKey {
system "stty", '-icanon';
system "stty", '-echo';
system "stty", 'eol', "\001";
my $inkey = getc(STDIN);
system "stty", 'echo';
system "stty", 'icanon';
system "stty", 'eol', '^@'; # ascii null
if ($inkey eq "[") {GetMsg();return;} #handles arrow key junk
return $inkey;
}
in all three cases, they work correctly within scripts that do not
read from STDIN -- I can put characters into the script interactively
and it works.
here is an example that works with out reading from STDIN
http://bowser.stanford.edu/software/todo/todo
However, when I put something like this
while (<>) {
read a bunch -o- lines from $_
}
earlier in the script -- the POSIX and readkey methds just hang
and
all the stty system calls give errors:
stty: standard input: Invalid argument
I'm missing something fundamental about STDIN / streams, etc. Not
sure where to read more on this.
please cc me on any replies if you can! THANKS! I appreciate your
time and help with this!
Jonathan Dugan
66@bowser.stanford.edu
------------------------------
Date: Sun, 15 Dec 2002 11:21:46 +0100
From: Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Subject: Re: Syntax of subroutine declarations, relating to use and variable scope
Message-Id: <athl42$144dfq$1@ID-171888.news.dfncis.de>
On zaterdag 14 december 2002 23:27 Jay Tilton wrote:
> Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl> wrote:
>
> : On zaterdag 14 december 2002 06:26 David B. Nagle wrote:
> :
> : > I was looking at the code in News::Article and came across some syntax
> : > that I had never encountered before.
> :
> :
> : You assumption is right. SelfLoader is irrellivant in this.
>
> Are you certain? The subroutine stubs look an awful lot like what is
> described in SelfLoader.pm. In which case, SelfLoader would have
> everything to do with the peculiarity.
Well, it *was* your assumption in the first place :-)
But, yes, it is irrelevant. The looks of the code are determined by the
coding style. Not by the syntax. A running Perl program is --by
definition-- syntactically right. Otherwise we wouldn't come very far,
would we? So the coding style makes a program look like it does. And it is
really irrelevant: 1 space, 4 spaces, semin-colon, leading semi-colon, etc,
it all doesn't matter. Perhaps the author of the package had a look at
SelfLoader and decided he felt comfortable with it's style and adopted it.
--
KP
koos _ pol @ raketnet nl
------------------------------
Date: Sun, 15 Dec 2002 10:30:59 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Test::More and overloading "=="
Message-Id: <9cmovucsj6urqdc7mckstqd7hd7ppbp678@4ax.com>
Daniel Berger wrote:
>use overload
> "==" => is_equal,
I would use either \&is_equal, or "is_equal" (quoted), but not just a
bareword.
> "fallback" => 1;
--
Bart.
------------------------------
Date: Sun, 15 Dec 2002 00:28:42 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: win2k total directory size, going down one level at least ?
Message-Id: <3DFC130A.7E33FF2A@earthlink.net>
doofus wrote:
>
> Besides doing something like this...
>
> my $dirsize;
>
> my %dir;
>
> tie %dir, 'IO::Dir', DIRECTORY_OF_DATA . $self->getUsername;
>
> foreach (keys %dir) {
>
> $dirsize += $dir{ $_ }->size;
>
> }
>
> ... does anybody know a better way of getting the size of a directory
> on win32 (win2k).
my $path = DIRECTORY_OF_DATA . $self->getUsername;
opendir( my ($dh), $path ) or die "opendir $path: $!;
my $dirsize = -s $path;
while( defined( my $filename = readdir $dh ) ) {
next if $filename eq "." or $filename eq "..";
$dirsize += -s "$path/$filename";
}
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
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 4265
***************************************