[21795] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3999 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 20 03:05:40 2002

Date: Sun, 20 Oct 2002 00:05:10 -0700 (PDT)
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, 20 Oct 2002     Volume: 10 Number: 3999

Today's topics:
    Re: coverting special characters (Tad McClellan)
        DBI module INSERT command problem <dgardiner@houston.rr.com>
    Re: DBI module INSERT command problem <nobody@nowhere.com>
    Re: DBI module INSERT command problem <dgardiner@houston.rr.com>
        general networking concept <smackdab1@hotmail.com>
    Re: How do I know whether a user specify STDIN or comma <krahnj@acm.org>
        How do I know whether a user specify STDIN or command i (Soon)
    Re: How do I know whether a user specify STDIN or comma <nobody@nowhere.com>
    Re: How to automate filling and submitting web forms. <bwalton@rochester.rr.com>
    Re: How to automate filling and submitting web forms. (Tad McClellan)
    Re: How to automate filling and submitting web forms. <s_grazzini@hotmail.com>
        How to parse command line keywords? <chris@home.com>
    Re: How to parse command line keywords? (Tad McClellan)
    Re: How to use wildcard with perl -pei file1.txt file2. (Tad McClellan)
        Initialize referenced lists with map function <yossi_shani@yahoo.com>
    Re: Initialize referenced lists with map function <krahnj@acm.org>
    Re: MLDBM and DB_BTREE <goldbb2@earthlink.net>
    Re: Perl2exe problem. <kevin@vaildc.net>
    Re: References to substrings <goldbb2@earthlink.net>
    Re: References to substrings <goldbb2@earthlink.net>
    Re: Separating stdout and stderr <goldbb2@earthlink.net>
    Re: Sockets through a proxy/firewall <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 19 Oct 2002 23:20:51 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: coverting special characters
Message-Id: <slrnar4bp3.21e.tadmc@magna.augustmail.com>

ted <tednospam94107@yahoo.com> wrote:

> Sorry for this cross-post. 


This *is not* a cross-post. 

There is only one newsgroup in the Newsgroups header.


> I posted a few days ago in comp.lang.perl but
> haven't had a response.


That's what happens when you use a newsgroup that was
removed *seven years* ago.    :-)


> How would I replace special characters like registration, trade or copyright
> marks?


The tr/// operator is good for working with characters:

   perldoc -f tr


> Are these Unicode characters?


If you were programming in Python or Java the answer
would be the same, so that question if off-topic in
a programming language newsgroup.

If you want to know about how Windows encodes characters,
then a Windows newsgroup would be the place to ask that.


> How would I replace other characters 


Using the tr///, or maybe the s///, operator.


> so that they show up correctly in a
> browser?


If you were programming in Python or Java the answer
would be the same, so that question if off-topic in
a programming language newsgroup.

If you want to know about how HTML encodes characters,
then an HTML newsgroup would be the place to ask that.


Once you've found out what you have, and what you want
it to be instead, _then_ you can code it up in Perl,
or ask here how to code it up.


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


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

Date: Sun, 20 Oct 2002 04:51:36 GMT
From: "Doug" <dgardiner@houston.rr.com>
Subject: DBI module INSERT command problem
Message-Id: <sDqs9.166641$Fw2.4913342@twister.austin.rr.com>

I have been unsuccessful in getting Access to do an INSERT command using DBI
that has a date component in it.  All my database logs show the date as
correct as I can think of it.  Here is a snippet from the log

[log snip]

 fff4c803:fff4cbdf EXIT  SQLPrepare  with return code -1 (SQL_ERROR)
  HSTMT               0x01ea207c
  UCHAR *             0x01b74518 [      96] "INSERT INTO sample_table
(description,project_id,date) VALUES ('just another test', '57','19 Oct
2002')"
  SDWORD                    96

  DIAG [37000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in
INSERT INTO statement. (-3502)

[/end log snip]

The following is caused by these lines:

my
@Month=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","D
ec");
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$year=$year+1900;
my $today_date="$mday $Month[$mon] $year";

$database_run=$dbh->do("INSERT INTO $table_type
(description,project_id,date) VALUES ('$description,
'$project_id','$today_date')");

if I do a prepare and leave the actual date out until the execute statement
as a bind parameter I get the same syntax error and execution but not
prepare.  If I remove the date section out of the insert entirely, the
database successfully inserts the data.  Only the date field is causing it.
I verified that the column name is exact, and that there isn't an input mask
in the database for that field, and compared it with the table that is
updated successfully and they both match.  I had this same problem a long
time ago but I can't remember for the life of me, how I fixed it, nor can I
remember the script that this was done in without error.

I've tried using dashes and moving the various portions of the date around,
with no results.  Oddly enough, this same script makes a call to update
another portion of the same database and successfully updates it with the
same date variable with no alterations to it.

Is there a weird quirk with inserts, something syntactical that I'm missing?
If this isn't the place to post this can you suggest a NG that I can post
this question?  I remember reading a long time ago, and my memory isn't the
greatest, that some databases have unique insert syntax, but I do not know
for sure.

Any comments, or suggestions would be appreciated, as I'm at wits end to
figure out why I have this syntax error, especially considering an update
with the same date variable in the same database and the same script works .
Thanks




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

Date: Sun, 20 Oct 2002 15:06:32 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: DBI module INSERT command problem
Message-Id: <UIqs9.57089$g9.164012@newsfeeds.bigpond.com>

Doug wrote in message ...
>I have been unsuccessful in getting Access to do an INSERT command using
DBI
>that has a date component in it.  All my database logs show the date as
>correct as I can think of it.  Here is a snippet from the log
>
>[log snip]
>
> fff4c803:fff4cbdf EXIT  SQLPrepare  with return code -1 (SQL_ERROR)
>  HSTMT               0x01ea207c
>  UCHAR *             0x01b74518 [      96] "INSERT INTO sample_table
>(description,project_id,date) VALUES ('just another test', '57','19 Oct
>2002')"
>  SDWORD                    96
>
>  DIAG [37000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in
>INSERT INTO statement. (-3502)
>
>[/end log snip]
>
>The following is caused by these lines:
>
>my
>@Month=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","
D
>ec");
>my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
>$year=$year+1900;
>my $today_date="$mday $Month[$mon] $year";
>
>$database_run=$dbh->do("INSERT INTO $table_type
>(description,project_id,date) VALUES ('$description,
Missing a ' after description for a start.

Try printing the entire SQL to stdout statement for debugging puurposes.

gtoomey




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

Date: Sun, 20 Oct 2002 05:38:30 GMT
From: "Doug" <dgardiner@houston.rr.com>
Subject: Re: DBI module INSERT command problem
Message-Id: <qjrs9.167215$Fw2.4922889@twister.austin.rr.com>

[snip]
> >
> >$database_run=$dbh->do("INSERT INTO $table_type
> >(description,project_id,date) VALUES ('$description,
> Missing a ' after description for a start.
>
> Try printing the entire SQL to stdout statement for debugging puurposes.
>
> gtoomey
>
>
I changed the database field names and then the INSERT statement to reflect
it.  Works now.  Probably, as I haven't researched all the SQL keywords,
date is reserved for special functions in SQL so that it got confused.  Only
guess I have for it.  And to your credit, I have the database trace log,
though cryptic is the most descriptive of the methods I'm using, since I can
check not just prepare statements, but execution too.  the error messages,
which I have automatically logged to a file, it just says that a syntax
error occurred, not even the line that it is tripping on.  But then again, I
have a debug mode set up in the script so that it spits out variable
changes, database calls and their returns everything to the browser window
for troubleshooting.




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

Date: Sun, 20 Oct 2002 03:43:15 GMT
From: "smackdab" <smackdab1@hotmail.com>
Subject: general networking concept
Message-Id: <nDps9.181552$S32.12410397@news2.west.cox.net>

FWIW: I am learning socket based communications, so I sometimes get confused
on the basics ;-)

That said:

I am currently playing around with a client and server that use TCP to pass
stuff back and forth.
I made it like a web server, where you connect, send stuff/recv stuff, and
disconnect.

This works good and seems be be very reliable...(I get the impression that
if something unexpected happens,
either the sender or receiver gets and error and then I just log the error
and continue)

But I am thinking of also having the option of permanent connections (it is
a good chance to learn more stuff!!)

This concerns me, because if there is problem with my logic, the server
could be waiting for a command
to end (I use a "special terminator line", but the client could mes
something up...so even future communications
to the server could be messed up)

Am I overly concerned?  Do I just need to make sure I QA my program enough
to eliminate these possibilites?

Is this a tradeoff that a web server writer had to consider?

I expect the permanent connection to be up 24x7 and if I notice an error I
want to try and re-connect and
then after a certain amount of time, I would just have the client die...

Thanks for any thoughts !!!!!!!!

ps
it will be a intranet app, not Internet...








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

Date: Sun, 20 Oct 2002 05:48:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How do I know whether a user specify STDIN or command invocation  argument filename
Message-Id: <3DB243DB.138702B6@acm.org>

Soon wrote:
> 
> I am writing a perl program similar like wc in UNIX.  How do I know
> whether the user provide input via <STDIN> (redirect a file from the
> command line) or via specifying one or more files as invocation
> arguments @ARGV?

You don't need to know if you use the <> special null filehandle.

perldoc perlop
[snip]
       The null filehandle <> is special: it can be used to
       emulate the behavior of sed and awk.  Input from <> comes
       either from standard input, or from each file listed on
       the command line.  Here's how it works: the first time <>
       is evaluated, the @ARGV array is checked, and if it is
       empty, `$ARGV[0]' is set to "-", which when opened gives
       you standard input.  The @ARGV array is then processed as
       a list of filenames.



John
-- 
use Perl;
program
fulfillment


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

Date: 19 Oct 2002 22:14:58 -0700
From: scyeang@hotmail.com (Soon)
Subject: How do I know whether a user specify STDIN or command invocation argument filename
Message-Id: <1a7061d5.0210192114.19acb295@posting.google.com>

I am writing a perl program similar like wc in UNIX.  How do I know
whether the user provide input via <STDIN> (redirect a file from the
command line) or via specifying one or more files as invocation
arguments @ARGV?


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

Date: Sun, 20 Oct 2002 15:36:57 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: How do I know whether a user specify STDIN or command invocation argument filename
Message-Id: <q9rs9.57097$g9.164231@newsfeeds.bigpond.com>

Soon wrote in message <1a7061d5.0210192114.19acb295@posting.google.com>...
>I am writing a perl program similar like wc in UNIX.  How do I know
>whether the user provide input via <STDIN> (redirect a file from the
>command line) or via specifying one or more files as invocation
>arguments @ARGV?

Count the number of files on the command line. If its zero, use stdin.

gtoomey




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

Date: Sat, 19 Oct 2002 22:06:53 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: How to automate filling and submitting web forms.
Message-Id: <3DB1D756.7020801@rochester.rr.com>

noname wrote:

> I am newbie (not spammer) and may be this question is too trivial..
> 
> I have list of URL pointing to webforms, which I want to fill and 
> submit. Of course, it is possible to go to each URL and fill and click 
> "Submit".
> 
> My question is, it there any application, using which I can automate, 
> it, i.e. by giving URLs and data to be filled on those webforms.
> 
> Or can it be done using Perl (I am yet to learn it)
> 
> Thanks in advance ;)
> 
> -E-
> 

You can do that with

      use LWP::UserAgent;

in Perl.  But it's probably not the best first Perl project around.
-- 
Bob Walton



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

Date: Sat, 19 Oct 2002 22:50:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to automate filling and submitting web forms.
Message-Id: <slrnar49vp.21e.tadmc@magna.augustmail.com>

noname <noname@nospam.com> wrote:

> I am newbie (not spammer) and may be this question is too trivial..


No, but it _is_ a Question that is Asked Frequently.

You are expected to check the Perl FAQs before posting
to the Perl newsgroup.


> My question is, it there any application, using which I can automate, 
                                                              ^^^^^^^^
> it, i.e. by giving URLs and data to be filled on those webforms.


   perldoc -q automate

      "How do I automate an HTML form submission?"


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


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

Date: 19 Oct 2002 16:28:43 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: How to automate filling and submitting web forms.
Message-Id: <3db1dc9b@news.mhogaming.com>

noname <noname@nospam.com> wrote:
> 
> I have list of URL pointing to webforms, which I want to 
> fill and submit. Of course, it is possible to go to each 
> URL and fill and click "Submit".
> 
> My question is, it there any application, using which I can 
> automate, it, i.e. by giving URLs and data to be filled on 
> those webforms.
> 
> Or can it be done using Perl (I am yet to learn it)
> 

You can automate a web client with the LWP suite 
of modules.

And there's HTML::Form, which lets you fill out
the form and click submit more or less the same
way a human being with a browser would do.

Both are (of course) on CPAN:

  http://search.cpan.org

HTH
-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Sun, 20 Oct 2002 03:12:15 GMT
From: chris <chris@home.com>
Subject: How to parse command line keywords?
Message-Id: <vk74ru4fg1inlo752huksc1h8fuhhcr41o@4ax.com>

Given command line
myscript.pl parm1=1234 parm2=abc

Do I parse this with GetOptions?


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

Date: Sat, 19 Oct 2002 22:58:02 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to parse command line keywords?
Message-Id: <slrnar4aea.21e.tadmc@magna.augustmail.com>

chris <chris@home.com> wrote:
> Given command line
> myscript.pl parm1=1234 parm2=abc
> 
> Do I parse this with GetOptions?


What is GetOptions?

(if it is a function in some module, then it might be helpful
 if you mentioned that module somewhere...
)


You can put them into a hash easily enough without any modules:

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

my %opt;
while ( $_ = shift ) {
   my($name, $value) = split /=/;
   $opt{$name} = $value;
}

print "$_ ==> $opt{$_}\n" for sort keys %opt;
-------------------------------------------


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


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

Date: Sat, 19 Oct 2002 22:44:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to use wildcard with perl -pei file1.txt file2.txt > bigfile?
Message-Id: <slrnar49kn.21e.tadmc@magna.augustmail.com>


[ Please put your comments *following* the quoted text
  that you are commenting on.

  Text rearranged back into the original chronology.
]


chris <chris@home.com> wrote:
> On Sat, 19 Oct 2002 11:19:42 -0500, tadmc@augustmail.com (Tad
> McClellan) wrote:
> 
>>In case you are saddled with working in an unsensible shell,
>>you might try this:
>>
>>
>>   perl -p -e "BEGIN{@ARGV=glob $ARGV[0]} print qq(code goes here\n)" "*.txt"


> This prints all the filenames, 


Why don't you just _tell us_ what shell you must work with?


> do I dare ask 


If you have spent 5 minutes looking for the answer yourself first,
then sure, ask away.


> how to print file content
> instead?
> 
>  perl -p -e "BEGIN{@ARGV=glob $ARGV[0]} print qq(<@ARGV>\n)" *.txt


Do you know what the -p switch does for you?

If not, then you should read up on it in perlrun.pod.


    perl -p -e "BEGIN{@ARGV=glob $ARGV[0]}" "*.txt"


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


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

Date: Sun, 20 Oct 2002 00:30:58 +0200
From: "yossi shani" <yossi_shani@yahoo.com>
Subject: Initialize referenced lists with map function
Message-Id: <1035066656.928258@sj-nntpcache-5>

Hi,
Maybe you could end my suffering.
I have a small list referenced to another two lists.
How can I initialize the first 4 arrays of entire lists to "" with map
function?
meanning:  @one[0..3] and @two[0..3] will be equall to ""
--------------
 my (@one, @two);
@list = ( \@one, \@two );
$list_r = \@list;

Thanks,
Yossi.




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

Date: Sat, 19 Oct 2002 22:43:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Initialize referenced lists with map function
Message-Id: <3DB1DFBD.1B7B853A@acm.org>

yossi shani wrote:
> 
> Maybe you could end my suffering.
> I have a small list referenced to another two lists.
> How can I initialize the first 4 arrays of entire lists to "" with map
> function?
> meanning:  @one[0..3] and @two[0..3] will be equall to ""
> --------------
>  my (@one, @two);
> @list = ( \@one, \@two );
> $list_r = \@list;


$ perl -le'
my (@one, @two);
@list = ( \@one, \@two );
$list_r = \@list;

@$_[0..3] = ("x") x 4 for @$list_r;
 
print "@$_" for @$list_r;
'
x x x x
x x x x



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 19 Oct 2002 23:56:13 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: MLDBM and DB_BTREE
Message-Id: <3DB2295D.4DD22F83@earthlink.net>

Andras Malatinszky wrote:
[snip]
> So how can I (can I?) combine DB_File's DB-BTREE option and MLDBM?

Instead of using MLDBM, use a filter to freeze and thaw the data.
Read perldoc perldbmfilter for more info.

use DB_File;
use Storable; # or Data::Dumper, and the Dump and eval functions.
tie my(%db), "DB_File", "sorted_food", O_RDWR|O_CREAT, 0640, $DB_BTREE;
(tie %db)->filter_store_value( sub { $_ = freeze($_) } );
(tie %db)->filter_fetch_value( sub { $_ =   thaw($_) } );
%db = (
   apple   => {color => 'red',       shape => 'round'},
   pizza   => {color => "don't ask", shape => 'flat'},
   sausage => {color => 'brown',     shape => 'oblong'},
);
while( my ($food, $info) = each %db ) {
   print "$food : color = $$info{red}, shape = $$info{shape}\n";
}
untie %db;

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 19 Oct 2002 23:25:43 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Perl2exe problem.
Message-Id: <kevin-AF2DAD.23254319102002@vienna7.his.com>

In article <7cd9e5d7.0210150556.332d8cad@posting.google.com>,
 michalowski@interred.de (MMichalow) wrote:

> Hi!
> 
> Seems like you are missing some perl modules:
> 
> > Converting 'testing.pl' to testing.exe
> > Warning: Can't locate Convert/EBCDIC.pm at D:\Perl\site\lib\Net\Cmd.pm line
> > 19
> > @INC = D:\Perl\lib, D:\Perl\site\lib, .
> Perl is looking for Convert::EBCDIC and cannot find it.
> 
> > Warning: Can't locate Mac/InternetConfig.pm at
> > D:\Perl\site\lib\Net\Config.pm line 40
> > @INC = D:\Perl\lib, D:\Perl\site\lib, .
> Perl is looking for Mac::InternetConfig and cannot find it.
> 
> The modules have to be installed in your @INC-path, that means they
> have to exist in 'D:\Perl\lib' or in 'D:\Perl\site\lib' or in your
> working directory ('.').

Yes, but unless the program is using either of these modules (unlikely, 
on Win32), this is nothing to worry about.  I get this message for 
things like File::Spec::VMS.  Perl2Exe is apparently pretty aggressive 
about finding modules to include...earlier versions were not, and 
frequently left things out.
-- 
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net   | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/


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

Date: Sun, 20 Oct 2002 02:04:55 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: References to substrings
Message-Id: <3DB24787.6AAE63E@earthlink.net>

Bill Smith wrote:
> 
> "Peter Erl" <p76e160a4@hotmail.com> wrote in message
> news:9fc0467f.0210190843.10ebfa83@posting.google.com...
> > I don't know if this is possible - web searches haven't helped and
> > my text books don't have a solution.
> >
> > I have a large blob of readonly data that I want to process as
> 
> Perl variables do not have a 'readonly' attribute.

Sure they do.   Consider what happens if you do:
   *x = \"$x";
and then try and modify $x.

Of course, this only works with $x being a package variable.  If you
want to do it with a lexical variable (one created with my()), then you
would need to use Devel::LexAlias, or Lexical::Alias.

   use Lexical::Alias;
   my $x = ....;
   alias_r \$x, \"$x";

Or, you could use the Scalar::Util module's readonly sub.

(The "Readonly" module doesn't really make variables readonly -- it ties
them to a class which prevents them from being modified)

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 20 Oct 2002 02:28:48 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: References to substrings
Message-Id: <3DB24D20.84DFD1A7@earthlink.net>

Peter Erl wrote:
> 
> I don't know if this is possible - web searches haven't helped and
> my text books don't have a solution.
> 
> I have a large blob of readonly data that I want to process as
> records without actually creating the records, ie a split
> operation that returns an array of references to the original
> data rather than a new list:
> 
> $data = "sdklfjsdkfj\ndkdfg\ndfjkgdgjk\n";
> 
> @refs = splitref(/\n/, $data);
> 
> print "yes\n" if (\$data == $refs[0]);
> 
> It's probably a FAQ somewhere, any suggestions or pointers
> appreciated.

What you want is to tie an array, such that examining elements of that
array extracts substrings on the original data.  You would, of course,
want to cache the indices of your newlines, for optimum speed.

package Tie::MySplitWithoutSplitting;

sub TIEARRAY {
   bless {
      data => \$_[1],
      indx => [0],
   }, $_[0];
}

sub FETCH {
   my ($self, $index) = @_;
   my $dataref = $self->{data};
   my $indices = $self->{indx};
   return if
       $$indices[-1] == length $$dataref and
       $index >= $#$indices;
   until( $#$indices > $index ) {
      my $i = index $$dataref, "\n", $$indices[-1];
      if($i < -1) {
         push @$indices, length $$dataref;
         return;
      }
      push @$indices, $i;
   }
   my $len = $$indices[$index+1] - $$indices[$index];
   return substr $$dataref, $$indices[$index], $len;
}

sub FETCHSIZE {
   my $self = shift;
   my $dataref = $self->{data};
   my $indices = $self->{indx};
   my $length = length $$dataref;
   until( $$indices[-1] == $length ) {
      my $i = index $$dataref, "\n", $$indices[-1];
      if($i < -1) {
         push @$indices, length $$dataref;
         last;
      }
      push @$indices, $i;
   }
   return scalar(@$indices) - 1;
}

package main;

tie my(@a), "Tie::MySplitWithoutSplitting",
   "sdklfjsdkfj\ndkdfg\ndfjkgdgjk\n";

print $a[0]; # prints "sdklfjsdkfj\n"
__END__
[untested]

Also, look into Tie::File, and DB_File.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 20 Oct 2002 00:38:43 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Separating stdout and stderr
Message-Id: <3DB23353.2A8C6D4A@earthlink.net>

Garry Williams wrote:
> 
> On 18 Oct 2002 14:59:56 -0700, Vilmos Soti <vilmos@vilmos.org> wrote:
> 
> > If I open a process with open, then is it possible somehow to access
> > the process' stdout and stderr separately?
> 
> This a FAQ.
> 
>   perldoc -q stderr
>     "How can I capture STDERR from an external command?"
> 
> Also see IPC::Open3, but pay special attention to the "This is very
> dangerous..." paragraph in that manual page.

I consider this bit of the documentation to be mere FUD -- especially if
you don't need to feed the program anything on it's stdin.

Yes, you have to be careful, but it's not going to magically deadlock
for no reason whatsoever.

The question is, in what order do you want to read parts of the stdout
and stderr of the program?

If you want to slurp one or both streams into variables, or process one
stream then the other, then there's no worry about deadlock -- as long
as you *don't* have both streams connected to pipes.  Eg:

use IO::File;
use IPC::Open3;
use Symbol qw(gensym);

{
   local *GRAB_ERR = ( IO::File->new_tempfile() || die $! );
   local *GRAB_OUT;
   my $pid = open3(gensym, \*GRAB_OUT, ">&GRAB_ERR",
      qw(tar cvf /dev/nst0 /mydir)
   );
   # my $out = do { local $/; <GRAB_OUT> };
   while( defined( my $line = <GRAB_OUT> ) ) {
      # process lines here.
   }
   waitpid( $pid, 0 ) or die "waitpid failed: $!";
   $? and die "Program exited unsuccessfully: \$? = $?";
   seek GRAB_ERR, 0, 0 or die "seek failed: $!";
   # my $err = do { local $/; <GRAB_ERR> };
   while( defined( my $line = <GRAB_ERR> ) ) {
      # process lines here.
   }
   close GRAB_ERR;
}

The important thing is that you redirect the stream you're going to
process second into a filehandle which "can't" fill up and block, such
as a handle to a tempfile.

If you need to process both out and err streams "simultaneously," then
you need to either use select() or IO::Select, or else fork(), or
redirect one stream or the other to another program, which is
essentially the same thing.  But you probably don't need this.

> Probably the FAQ answer is best.  The FAQ claims it's answer is the
> "easiest and safest".

The FAQ answer you're refering to is ok *if* you don't mind waiting for
the program to entirely finish before you read the data from it.  And if
you don't mind all of the program's stdout and stderr temporarily
residing in the filesystem.  If the program produces a gig or two on
stdout, and a tiny bit on stderr, then you *really* won't want to use
the FAQ answer.  And you have to not mind it invoking the shell (which
may mean escaping some or all of the arguments to your program).

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 19 Oct 2002 22:05:05 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sockets through a proxy/firewall
Message-Id: <3DB20F51.5F8E1EED@earthlink.net>

Nigel wrote:
> 
> I have two simple scripts for passing pdf documents from one machine
> to another using sockets.  These work perfectly well for most
> machines, but from time to time I'm going to want to get them through
> to a machine behind a corporate firewall.  Assuming I know the IP
> address of the firewall, and the local Ip address of the machine
> itself, is there a simple way of modifying cli.pl (below) to pass the
> documents through

Configure the firewall so that when you connect to a specific port on
the firewall, it will forward that connection to port 5050 of the
particular machine you want to get to, that's hidden behind it.

Or, configure the firewall so that connections on port 5050 are always
passed through.

No matter what, you're not going to get through the firewall unless it
allows you through, which will probably require that it's configuration
be changed.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

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


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