[22696] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4917 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 30 14:06:55 2003

Date: Wed, 30 Apr 2003 11:05:09 -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           Wed, 30 Apr 2003     Volume: 10 Number: 4917

Today's topics:
        $::var notation <ben_altman@deadspam.com>
    Re: $::var notation (Hunter Johnson)
    Re: $::var notation <bigj@kamelfreund.de>
    Re: $::var notation <ben_altman@deadspam.com>
    Re: $::var notation <ben_altman@deadspam.com>
        A cool computer forum <ngszeli@hotmail.com>
    Re: A cool computer forum <uri@stemsystems.com>
    Re: complex text/file search. help please!!! <mbudash@sonic.net>
    Re: complex text/file search. help please!!! (William R. Mattil)
    Re: DBD-Pg issue <samik@frKKshKll.org>
    Re: Elegant test for A in B OR B in A? (Anno Siegel)
        Help: Use of uninitialized value??? (entropy123)
    Re: Help: Use of uninitialized value??? <john.thetenant-s@moving-picture.com>
    Re: Is it possible to pass @somethig and $something_els <john.thetenant-s@moving-picture.com>
    Re: Is it possible to pass @somethig and $something_els <uri@stemsystems.com>
        Net::SSH::Perl and Windows no_spam_please@usa.com
        panic: frexp at blib/lib/Text/Reform.pm line 149 <prlawrence@lehigh.edu>
        Parsing multiple files and mixing the data <r1534c@motorola.com>
    Re: Perl - DBI - How to store connection info in a sepa <Juha.Laiho@iki.fi>
    Re: Perl Microsoft Server incompatibility? <mdudley@execonn.com>
    Re: Perl Microsoft Server incompatibility? <simon.andrews@bbsrc.ac.uk>
    Re: Perl Microsoft Server incompatibility? <mdudley@execonn.com>
    Re: search, replace and insert. <w.koenig@acm.org>
    Re: setting a variable from a line in a file <peter_wilson@mail.com>
    Re: Subtracting strings [long post] (Quantum Mechanic)
    Re: Subtracting strings [long post] (Quantum Mechanic)
        waste of time (smugbuster)
    Re: waste of time <mbudash@sonic.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Apr 2003 10:19:59 -0500
From: Ben <ben_altman@deadspam.com>
Subject: $::var notation
Message-Id: <b8opiv$bsh6u$1@ID-121117.news.dfncis.de>

I encountered this in a perl script and am wondering if someone can tell 
me what it does and where to find out more about it.

Thanks,
Ben



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

Date: 30 Apr 2003 15:39:00 GMT
From: jhunterj@lexis-nexis.com (Hunter Johnson)
Subject: Re: $::var notation
Message-Id: <b8oqmk$6qc$1@mailgate2.lexis-nexis.com>

In article <b8opiv$bsh6u$1@id-121117.news.dfncis.de>,
Ben  <newsgroup3.replies.benaltw@xoxy.net> wrote:

> I encountered [$::var notation] in a perl script and am wondering if
> someone can tell me what it does and where to find out more about
> it.

[Go ahead and use your subject in the body text too.]

$::var is the same as $main::var. Check out the article Coping with
Scoping:

http://perl.plover.com/FAQs/Namespaces.html

Hunter
--
J. Hunter Johnson        | "A little consistent wholesome modeling and
jhunterj@lexisnexis.com  |   costly servanthood are worth millions of
(937) 865-6800 x55385    |    true words harshly spoken."
Lexis-Nexis, Dayton, OH  |                               -- Ron Sider




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

Date: Wed, 30 Apr 2003 16:52:01 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: $::var notation
Message-Id: <pan.2003.04.30.14.52.00.679573@kamelfreund.de>

Ben wrote at Wed, 30 Apr 2003 10:19:59 -0500:

> I encountered this in a perl script and am wondering if someone can tell 
> me what it does and where to find out more about it.

$::var notation

stands for the variable called 'var' from the current package.
In most cases it will be the same like $var
unless you have a lexical scoped variable $var and a global variable in
this package with the same name.
E.g.

perl -e '$x = 5; { my $x = 4; print $::x }'

prints 5

where 

perl -e '$x = 5; { my $x = 4; print $x }'

prints 4.


In general it's quite the same like with package variables like
$Data::Dumper::Indent
where you address a global variable from an other package.
$::xyz is just the way like you address global variable from your own
package.


Greetings,
Janek


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

Date: Wed, 30 Apr 2003 11:30:31 -0500
From: Ben <ben_altman@deadspam.com>
Subject: Re: $::var notation
Message-Id: <b8otne$c8pmj$1@ID-121117.news.dfncis.de>

Hunter Johnson wrote:
> In article <b8opiv$bsh6u$1@id-121117.news.dfncis.de>,
> Ben  <newsgroup3.replies.benaltw@xoxy.net> wrote:
> 
> 
>>I encountered [$::var notation] in a perl script and am wondering if
>>someone can tell me what it does and where to find out more about
>>it.
> 
> 
> [Go ahead and use your subject in the body text too.]
> 
> $::var is the same as $main::var. Check out the article Coping with
> Scoping:
> 
> http://perl.plover.com/FAQs/Namespaces.html

Thanks. Now to figure out why the author didn't just write $var...

regards,
Ben



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

Date: Wed, 30 Apr 2003 11:48:34 -0500
From: Ben <ben_altman@deadspam.com>
Subject: Re: $::var notation
Message-Id: <b8oup3$c7bba$1@ID-121117.news.dfncis.de>

Janek Schleicher wrote:
> $::var notation
> 
> stands for the variable called 'var' from the current package.
> In most cases it will be the same like $var
> unless you have a lexical scoped variable $var and a global variable in
> this package with the same name.
> E.g.
> 
> perl -e '$x = 5; { my $x = 4; print $::x }'
> 
> prints 5
> 
> where 
> 
> perl -e '$x = 5; { my $x = 4; print $x }'
> 
> prints 4.

The script has "local ($::var) = 0;" at the top and some functions 
defined within that use it. It would probably be required in another 
script (though grepping for it was unhelpful). There doesn't seem to be 
a need for $:: in this instance though unless I am missing something.

regards,
Ben



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

Date: 30 Apr 2003 23:19:36 +0800
From: Ng Sze Li <ngszeli@hotmail.com>
Subject: A cool computer forum
Message-Id: <3eafe988_1@news.tm.net.my>

Here's a Forum Talking About
Computer Help (Technicians)
Hardware & Software
Programming
Internet
& also the Cellphone

http://ngszeli.com/forum/index.php?s=21ae134f8749959a311508ea3fe54cc3&c=5

---
MAF Anti-Spam ID: 20030224072256P2s0LdM5



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

Date: Wed, 30 Apr 2003 15:28:08 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A cool computer forum
Message-Id: <x7znm8vwc8.fsf@mail.sysarch.com>

>>>>> "NSL" == Ng Sze Li <ngszeli@hotmail.com> writes:

  NSL> Here's a Forum Talking About

  NSL> MAF Anti-Spam ID: 20030224072256P2s0LdM5

do i detect some hypocrisy here?

bugger off!

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 30 Apr 2003 16:00:27 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: complex text/file search. help please!!!
Message-Id: <mbudash-0F7AFB.09002630042003@typhoon.sonic.net>

In article <da063e5d.0304300518.6bd29980@posting.google.com>,
 molivier@caregroup.harvard.edu (supportgeek) wrote:

> > 
> > this should get you started:
> > 
> > open (D, "data") or die ("Can't open data: $!");
> > local $/ = "\f";
> > while (<D>) {
> >   if (/^7002/m) {
> >     my @lines = split /\n/;
> >     print shift @lines, "\n";
> >     foreach (@lines) {
> >       print "$_\n" if /^7002/;
> >     }
> >   }
> > }
> > 
> > hth-
> 
> Michael. 
> 
> That code works great. It's just what I need to get started. Thanks a
> million.

glad to help

> If you get a chance, would you mind explaining to me how it works. I
> feel guilty using it w/o fully understanding it!
> 
> I looked up $/ the input record separator, but I'm not sure how your
> getting it to print out the first line of the record (which is the
> line that I need). Is that just how the $/ works? 

no - i'll explain it line by line:

# open the file for reading, or die if you can't, telling why ($!).
open (D, "data") or die ("Can't open data: $!");

# set the record separator to formfeed, so when reading the file, each
# read gets you everything up to a formfeed.
local $/ = "\f";

# keep reading a record into $_ until EOF
while (<D>) {

  # if the record contains any line that starts with 7002, continue.
  # note the 'm' modifier on the regex. this is necessary because there
  # are 'm'ultiple lines (strings terminated by newlines) per record. the
  # regex won't work for this purpose without it, unless the first line
  # starts with 7002.
  if (/^7002/m) {

    # split the record into an array of lines.             
    my @lines = split /\n/;

    # remove and print the first array element.
    print shift @lines, "\n";

    # for each remaining array element, print it if it starts with 7002.
    foreach (@lines) {
      print "$_\n" if /^7002/;
    }
  }
}

# close the file
close (D);

> Also would it be possible for me to print the entire record if I find 
> the /^7002/ match in it.

easy. same thing except:

while (<D>) {
  print if (/^7002/m);           
}

hth-

-- 
Michael Budash


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

Date: 30 Apr 2003 17:53:26 GMT
From: wrm@rrscfi1.irngtx.tel.gte.com (William R. Mattil)
Subject: Re: complex text/file search. help please!!!
Message-Id: <b8p2im$4hb$1@news.gte.com>

In article <mbudash-0F7AFB.09002630042003@typhoon.sonic.net>,
Michael Budash  <mbudash@sonic.net> wrote:
> open (D, "data") or die ("Can't open data: $!");
> local $/ = "\f";
> while (<D>) {
>   if (/^7002/m) {
>     my @lines = split /\n/;
>     print shift @lines, "\n";
>     foreach (@lines) {
>       print "$_\n" if /^7002/;
>     }
>   }
> }

Michael,

I found this very interesting and informative but a question. The
Original poster wanted something like:

#Example of the data I need to pull

#from record 1
145 Main St                      001-34562032-100         831
7002     SPARK PLUG         45345
7002     SPARK PLUG         234234

#from record 3
145 Main St                      001-6734232-100         831
7002     SPARK PLUG         4342534523

And from the data he presented:

145 Main St                      001-34562032-100         831
7002     SPARK PLUG         45345
7002     SPARK PLUG         234234
7002     SPARK PLUG         4342534523

The customer number from record three got lost in the shuffle. Am
I understanding this  correctly ? 

Best Regards

Bill


-- 

William R. Mattil       | Failure is not an Option ... It's bundled 
Sr. System Aministrator | with all Microsoft Products               
(972) 399-4106          |                                           


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

Date: Wed, 30 Apr 2003 10:17:00 -0500
From: Samik Raychaudhuri <samik@frKKshKll.org>
Subject: Re: DBD-Pg issue
Message-Id: <b8opdd$j0k$1@news.doit.wisc.edu>

Seems like some permission issue or might be soe environment variable. Check against this one, if you have missed something: http://samik.freeshell.org/prog/dbase/index.html
HTH
-Samik

On 4/28/2003 9:54 PM, IKNIR wrote:
> am struggling with the DBD-Pg installation almost 3 weeks. Please
> somebody out there could help me. Thank you in advance.
> 
> I have installed the following on WINDOWS XP:
> CYGWIN
> POSTGRESQL 7.3.1
> APACHE 2.0.43
> ACTIVESTATE PERL 5.8
> DBI 1.35 (Installed using cygwin)
> DBD-Pg 1.22 (Installed using cygwin perl makefile.pl, make, make test,
> and make install)
>  
> I have no problem in running the following script in CYGWIN:
> 
> #!/perl/bin/perl -w
> BEGIN {
>   push(@INC, 'C:/cygwin/lib/perl5/site_perl/5.6.1/cygwin-multi');
> }
> use DBI;
> use DBD::Pg;
> print "Content-type: text/html\n\n";
> print "hi";
>  
> However, I cannot run this using the browser. I get the following
> error.
>  
> Can't load 'C:/cygwin/lib/perl5/site_perl/5.6.1/cygwin-multi/auto/DBD/Pg/Pg.dll'
> for module DBD::Pg:load_file:The specified module could not be found
> at C:/Perl/lib/DynaLoader.pm line 229.
> 
> What am I doing wrong? Why this works in CYGWIN but not in browser?

-- 
Samik Raychaudhuri
University of Wisconsin, Madison
http://samik.freeshell.org/

To email me, replace 'K' with 'e' in the 'From' field.



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

Date: 30 Apr 2003 17:34:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Elegant test for A in B OR B in A?
Message-Id: <b8p1f9$7hb$1@mamenchi.zrz.TU-Berlin.DE>

Tina Mueller  <usenet@tinita.de> wrote in comp.lang.perl.misc:
> Sara <genericax@hotmail.com> wrote:
> 
> > I have an array of names and a scalar. Basically I want to know if the
> > scalar is in the array of names, but unfortunately, either the scalar
> > or the array elements can be abreviated.
> 
> for (@array) {
>  print unless index($x,$_) && index ($_,$x)
> }

Now, wait...  So index() is 0 exactly if the second argument is found
at position 0, that is, it is a prefix of the first one.  Therefore
index() is true if it isn't a prefix, so index() && index() is true
if neither is a prefix of the other, so "print unless" prints the right
thing.

Satisfactory, as Nero Wolfe would say.  A short, symmetric, and presumably
fast solution to a recurring problem.  This is probably what Sara had
in mind.

Just a pity it's a little hard to read.  It's amazing what a single
negation can do to obfuscate logic.  If one were to define

    sub prefix {
        my( $pre, $str) = @_;
        index( $str, $pre) == 0;
    }

and then said

    # ...
        print if prefix( $x, $_) or prefix( $_, $x);

there would be no such problem.  But compared to your original it lacks
severely in the snazziness department.

Anno


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

Date: 30 Apr 2003 10:13:39 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: Use of uninitialized value???
Message-Id: <90cdce37.0304300913.68437148@posting.google.com>

Hey all,

I'm a newbie here and just trying to make a small program work. It
works, but there is this error 'Use of uninitialized value' I always
get it when I use arrays. Scalars I usually set $my_scalar=0. Arrays,
on the other hand, I can't seem to properly initialize. I just want an
empty array I can add strings to at will throughout my program...

If you can help me out I much appreciate...

Thanks,
Entropy


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

Date: Wed, 30 Apr 2003 18:39:57 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Help: Use of uninitialized value???
Message-Id: <20030430183957.6896baf0.john.thetenant-s@moving-picture.com>

On 30 Apr 2003 10:13:39 -0700
email_entropy123@yahoo.com (entropy123) wrote:
>
> Hey all,
> 
> I'm a newbie here and just trying to make a small program work. It
> works, but there is this error 'Use of uninitialized value' I always
> get it when I use arrays. Scalars I usually set $my_scalar=0. Arrays,
> on the other hand, I can't seem to properly initialize. I just want an
> empty array I can add strings to at will throughout my program...
> 
> If you can help me out I much appreciate...
> 
> Thanks,
> Entropy

use warnings;
use strict;
my @stringsArray=(); #here's your empty array
push @stringsArray, 'foo'; #initialised

print $stringsArray[1], "\n"; #whoa, uninitialised value!


you may be explicitly accessing an array index which
you haven't created (or have filled with an undefined
value.)  using warnings and strict should help you sort 
it-- else post more code.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Wed, 30 Apr 2003 16:03:00 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Is it possible to pass @somethig and $something_else to sub
Message-Id: <20030430160300.19ab623d.john.thetenant-s@moving-picture.com>

On Wed, 30 Apr 2003 14:40:39 GMT
Uri Guttman <uri@stemsystems.com> wrote:
>
> >>>>> "T" == Tony  <anthony@movielink.net.au> writes:
> 
>   T> This one was the one that worked out best:-)
> 
>   T> my @list = ("something","$something_else");
>   T> my $string = "a_string";
> 
>   T> process( $string,\@list);
> 
>   T> sub process
>   T> 	{
>   T> 	my ( $str, $a_ref ) = @_;
>   T> 	my @Array = @{$a_ref};
> 
> why copy the array if all you want is to print it? you can just access
> it in the print like you do here.
> 
>   T> 	print "$str @Array\n;
> 
> 	print "$str @{$a_ref}\n;
> 
>   T> For some reason the print function (To let me see things)
>   T> showed the @Array list without the quotes so I thaught it was cactus...
> 
> what quotes? print never adds quote so why are you expecting them?
> 

maybe he means the missing end quote from his (and your) print statement.
or the quotes around each element when he initialised @list.
or maybe some quotes contained in one of the @list elements.
i bet he means the middle one, but i might lose my shirt.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Wed, 30 Apr 2003 15:22:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Is it possible to pass @somethig and $something_else to sub
Message-Id: <x74r4gxb6h.fsf@mail.sysarch.com>

>>>>> "JS" == John Strauss <john.thetenant-s@moving-picture.com> writes:

  >> >>>>> "T" == Tony  <anthony@movielink.net.au> writes:
  >> 
  >> 
  T> my @list = ("something","$something_else");
                             ^               ^
didn't notice that too. don't quote scalars like that. it is not needed
and can cause bugs.

  JS> maybe he means the missing end quote from his (and your) print
  JS> statement.  or the quotes around each element when he initialised
  JS> @list.  or maybe some quotes contained in one of the @list
  JS> elements.  i bet he means the middle one, but i might lose my
  JS> shirt.

i would bet on that too. maybe some dirty socks if not my shirt. :)

and i hate to think that the OP has a 'working' solution and won't come
back to this thread to learn more.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 30 Apr 2003 17:20:28 GMT
From: no_spam_please@usa.com
Subject: Net::SSH::Perl and Windows
Message-Id: <pq00bvkrd4ob492kg1spm0uochr5915p5t@4ax.com>

I'm trying to use Net::SSH::Perl module to ssh from Linux to Windows
box running ssh server.
The code goes like this :

my $ssh = Net::SSH::Perl->new('ssh-server', debug=>2, protocol=>'2',
                    options=>[
                 "IdentityFile /home/cthulhu/.ssh/identity",
                 "UserKnownHostsFile /home/cthulhu/.ssh/knownhosts",
                 "BatchMode yes"
                    ]);

  $ssh->login('cthulhu');
  my ($stdout, $stderr, $exit) = $ssh->cmd("cmd dir /c");

  print "$stdout   $stderr   $exit \n";



It seems to login successfully but I never get the expected list of
files on the server. $stout and $stderr variables are empty , $exit
contains 0.
If I use $ssh->shell I get to command prompt on windows and can type
commands but it never gives me any replies.
 I can use regular ssh command to login to server but perl script
doesn't work. I would really appreciate any ideas







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

Date: Wed, 30 Apr 2003 06:46:04 -0500
From: Phil R Lawrence <prlawrence@lehigh.edu>
Subject: panic: frexp at blib/lib/Text/Reform.pm line 149
Message-Id: <20030430064604.7408b755.prlawrence@lehigh.edu>

Hi,

Trying to install Text::Reform 1.10.  Anyone have an idea what the problem is here?

   Text::Reform fails make test:

cpan> install Text::Reform
Running install for module Text::Reform
Running make for D/DC/DCONWAY/Text-Reform-1.10.tar.gz
Fetching with LWP:
 
ftp://ftp.lehigh.edu/pub/perl/CPAN/authors/id/D/DC/DCONWAY/Text-Reform-1.10.tar.gz
Checksum for 
/home/local/perl/.cpan/sources/authors/id/D/DC/DCONWAY/Text-Reform-1.10.tar.gz 
ok
[...]
   CPAN.pm: Going to build D/DC/DCONWAY/Text-Reform-1.10.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for Text::Reform
[...]
Running make test
         PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib 
-I/home/local/perl/lib/5.6.1/aix -I/home/local/perl/lib/5.6.1 test.pl
1..63
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10
ok 11
ok 12
ok 13
ok 14
ok 15
ok 16
ok 17
ok 18
ok 19
ok 20
ok 21
ok 22
ok 23
ok 24
ok 25
ok 26
panic: frexp at blib/lib/Text/Reform.pm line 149.
make: The error code from the last command is 255.


Stop.
   /usr/bin/make test -- NOT OK
Running make install
   make test had returned bad status, won't install without force


Here is line 149:
    next CHUNK if !$args{autocentre} || @$chunk < 2;

Thanks,
Phil R Lawrence


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

Date: Wed, 30 Apr 2003 18:29:47 +0100
From: "Martin McKenny" <r1534c@motorola.com>
Subject: Parsing multiple files and mixing the data
Message-Id: <b8p0p3$bnb$1@newshost.mot.com>

Hi All,

I want to read in the lines of multiple files in parallel in order to merge
the elements of each file.

So if we have three files with listed data as follows:

File1 contains data: a1 a2 a3
File2 contains data: b1 b2 b3
File3 contains data: c1 c2 c3

I want to merge these to get a file containing

Output file : a1 b1 c1 a2 b2 c2 a3 b3 c3

I need to do this as effieciently as possible as the files in question
contain hundreds of thousands of data elements.

Any help appreciated
MMK




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

Date: Wed, 30 Apr 2003 17:22:01 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Perl - DBI - How to store connection info in a separate file
Message-Id: <b8p0fh$2jh$2@ichaos.ichaos-int>

deepak10000@hotmail.com (deepak p) said:
>I was wondering if anyone knows the syntax to include DBI connection
>info in a separate file and make a call to it from a perl dbi script.

Either considet the separate file as data (configuration file):
- open
- read
- parse
- set variable values according to parse results
- close

 ... or, perhaps, the 'do EXPR' structure; see the perl documentation
for that (perldoc -f do).
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Wed, 30 Apr 2003 11:22:25 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: Re: Perl Microsoft Server incompatibility?
Message-Id: <3EAFEA31.964C3FDB@execonn.com>

I just figured out that brain dead Windows requires a binmode on the file
before accessing.  It now loads the whole file, but it still doesn't work.
From viewing what I am getting with what is being sent, it appears that
extraneous returns are being entered throughout the file mucking up the pdf
file.

Marshall

Marshall Dudley wrote:

> I have a perl script that I have installed on numerous unix machines
> without any problems.
>
> However, I am now trying to install it on a Microsoft machine, and am
> unable to get it to work.
>
> The code that is failing is:
>
> while (sysread(FILE,$max,$bufsize)) {
>         print $max;
> }
>
> For a pdf file, this will print the entire pdf file (about 1.3 Meg.) and
> displays properly on a UNIX machine, but on the MS machine it only
> outputs a little over 2K, then stops, generating an error with the pdf
> viewer called by the browser.
>
> Any idea what the problem might be. I have spent the last two days on
> this off and on to no avail.  I don't understand why it would work under
> Unix but not MS.
>
> The entire code can be seen at http://king-cart.com/download.pl
>
> I also found that you cannot do a die function with MS like you can
> UNIX.  MS will output the error before the content-type header resulting
> in an error to the browser.
>
> Thanks,
>
> Marshall



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

Date: Wed, 30 Apr 2003 16:33:12 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Perl Microsoft Server incompatibility?
Message-Id: <3EAFECB8.7080501@bbsrc.ac.uk>



Marshall Dudley wrote:
> I have a perl script that I have installed on numerous unix machines
> without any problems.
> 
> However, I am now trying to install it on a Microsoft machine, and am
> unable to get it to work.
> 
> The code that is failing is:
> 
> while (sysread(FILE,$max,$bufsize)) {
>         print $max;
> }


perldoc -f binmode

You are probably getting windows line endings substituted for unix ones 
in an inappropriate place.  You should binmode both the input and output 
filehandles before using them.

binmode FILE;
binmode STDOUT;

while (sysread(FILE,$max,$bufsize)) {
         print $max;
}

Hope this helps

Simon.



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

Date: Wed, 30 Apr 2003 11:35:42 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: Re: Perl Microsoft Server incompatibility?
Message-Id: <3EAFED4E.535CB923@execonn.com>

Thanks, it works now.  Dang I hate MS products.

Marshall

Simon Andrews wrote:

> Marshall Dudley wrote:
> > I have a perl script that I have installed on numerous unix machines
> > without any problems.
> >
> > However, I am now trying to install it on a Microsoft machine, and am
> > unable to get it to work.
> >
> > The code that is failing is:
> >
> > while (sysread(FILE,$max,$bufsize)) {
> >         print $max;
> > }
>
> perldoc -f binmode
>
> You are probably getting windows line endings substituted for unix ones
> in an inappropriate place.  You should binmode both the input and output
> filehandles before using them.
>
> binmode FILE;
> binmode STDOUT;
>
> while (sysread(FILE,$max,$bufsize)) {
>          print $max;
> }
>
> Hope this helps
>
> Simon.



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

Date: Wed, 30 Apr 2003 11:48:46 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: search, replace and insert.
Message-Id: <3EAF9BFE.4020904@acm.org>

Kurtis D. Rader wrote:
> 
> I'm surprised no one has suggested slurping and operating on the whole
> file. If the input is potentially larger than what you can fit in memory
> then this is a bad idea. But an Apache configuration file is all but
> guaranteed to be small enough that slurping it all into memory is not going
> to be a problem.
> 
>     perl -0777 -pi -e 'whatever'
> 
> The "-pi" mechanism isn't constrained to working line by line.

the perlrun description of option -0 may be not valid for all 
environments. The code point 0x1ff describes a legal character.

code    01FF
name    LATIN SMALL LETTER O WITH STROKE AND ACUTE
block   Latin Extended-B
script  Latin

Winfried Koenig


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

Date: Wed, 30 Apr 2003 16:30:27 +0000 (UTC)
From: "Peter Wilson" <peter_wilson@mail.com>
Subject: Re: setting a variable from a line in a file
Message-Id: <b8otn3$gun$1@titan.btinternet.com>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbatr74.23h.tadmc@magna.augustmail.com...
> Peter Wilson <peter_wilson@mail.com> wrote:
> > "Tad McClellan" <tadmc@augustmail.com> wrote in message
> > news:slrnbarhpu.inp.tadmc@magna.augustmail.com...
> >> Peter Wilson <peter_wilson@mail.com> wrote:
> >>
> >> > open(filelist,$list_of_files_filename)
> >>
> >>
> >> There are three things wrong with that line of code.
> >>
> >> Do you know what they are?
>
> [snip full-quote]
>
> > Yeah but it made the point and he
>
>
> There are hundreds/thousand of other people here, reading posts and
> copying the code they see. It should be good code.
>
>
> > was happy.
>
>
> He'll be less happy when the open() fails or when a new version
> of Perl includes a filelist() function.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

ok point taken, I will be more careful.




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

Date: 30 Apr 2003 08:11:31 -0700
From: quantum_mechanic_1964@yahoo.com (Quantum Mechanic)
Subject: Re: Subtracting strings [long post]
Message-Id: <f233f2f0.0304300711.49ec4079@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3eaf647b.568817771@news.erols.com>...
> quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote:
> : [snip] ...The 2nd string must be a
> : proper substring of the 1st -- if there are characters in the 2nd
> : string not in the 1st, or there is an excess of one or more characters
> : in the 2nd string compared to the 1st, a failing result is returned.
> 
> That's not the usual interpretation of "substring," but the
> explanation is clear enough.

Sorry. "Subset" doesn't fit very well either. "Sub-anagram"?

> 
> : Two less-than-satisfactory methods I've come up with:
> 
> What exactly do you find unsatisfactory about them?

I was hoping for a nice one-liner-ish solution, with an RE or a map or
something. [I'm overly partial to map for some reason.]

> 
> : #### 1: character set hashes ####
> :   # create a hash of char counts based on the given string
>  [snip]
> :   # compare 2 string "sets", return the difference
> :   # note that counts of the 2nd are subtracted from the first
> :   # if a negative count occurs, return 0 as a scalar
>  [snip]
> :   # return a string given a char set
>  [snip]
> :   # subtract one string from another
> [snip]
> 
> The gist of that algorithm is peachy, but the rendition is spaghetti.

I understand reducing them to one sub, but I'd be interested in more
commentary on the "spaghetti" comment. Perhaps it's just my need for
extra delimiters and whitespace?

Yes, all of the subs are used, but only once or twice, other than
being called from the main sub. I see I can just use string_diff with
an empty 2nd string to get a character count of the 1st argument, with
negligible speed reduction.

> Unless each of those subs is used for other purposes, I'd just hammer
> them all into a single sub.  In fact, the result is so short that I'd
> do that anyway.
> 
>     sub string_diff {
>         my %seen;
>         # Values of %seen will be the difference in character counts
>         # between the first string and the second.
>         my @foo = ( undef, @_ ); # so we can use indeces 1 and -1
>         for my $i (1, -1) {
>             $seen{$_} += $i for $foo[$i] =~ /./g;
>         }

Nice one. 

Small critique...The RE here will be slower than split, won't it?
[Don't use the RE engine when a built-in already exists.]

              $seen{$_} += $i for split //, $foo[$i];

Of course, my overuse of block-style map and grep is a mark against me
;) But I like boundary markers.

>         # Verify that all letters in the second word
>         # appear in the first.
>         $_ < 0 && return 0 for values %seen;
>         # Smush remaining letters into a return string.
>         return join '', map $_ x $seen{$_}, keys %seen;
>     }
>  
> : #### 2: substr and index
[snip]
> 
> That one's a little verbose, but not shabby at all.  For my tastes,
> I'd use s/// instead of index/substr.
> 
>     sub string_diff {
>         my( $one, $two ) = @_;
>         $one =~ s/$_// or return 0 for( $two =~ /./g );
>         return $one;
>     }

[Again, use split instead of /./g.]

This one I'll certainly steal. 

Thanks,
-QM


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

Date: 30 Apr 2003 08:15:50 -0700
From: quantum_mechanic_1964@yahoo.com (Quantum Mechanic)
Subject: Re: Subtracting strings [long post]
Message-Id: <f233f2f0.0304300715.768a3186@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3EAF85F2.33EA1FF2@acm.org>...
> Quantum Mechanic wrote:
> > 
[snip]
> sub diff {
>   my ( $s, $c ) = @_;
>   $s =~ s/\Q$_\E// or return 0 for split //, $c;
>   return $s;
>   }

Yes, very good. I'll buy it.

I like the \Q\E too.

Thanks,
-QM


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

Date: 30 Apr 2003 10:48:01 -0700
From: smugbuster@hotmail.com (smugbuster)
Subject: waste of time
Message-Id: <677cff64.0304300948.7e8878c4@posting.google.com>

your little newsgroup or whatever you call it is a waste of time for
anybody trying to learn anything new.

legitimate questions are disparaged, ridiculed, and made fun of.
what's wrong with you people? you were all newbies once!

my guess is that half of you don't know what you're talking about
anyway.

don't you have anything better to do than to get online and "flame"
people that may not have as much knowledge of the subject as you.
pathetic.

i suggest you get a life. you're all a little too smug for your own
good.

oh, also, i guess i'm not cool because i don't have a witty quip at
the end of my message, or use case sensitive words or end plural words
with a string of "z's."

jack


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

Date: Wed, 30 Apr 2003 17:51:24 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: waste of time
Message-Id: <mbudash-DD6FFC.10512330042003@typhoon.sonic.net>

In article <677cff64.0304300948.7e8878c4@posting.google.com>,
 smugbuster@hotmail.com (smugbuster) wrote:

> your little newsgroup or whatever you call it is a waste of time for
> anybody trying to learn anything new.
> 
> legitimate questions are disparaged, ridiculed, and made fun of.
> what's wrong with you people? you were all newbies once!
> 
> my guess is that half of you don't know what you're talking about
> anyway.
> 
> don't you have anything better to do than to get online and "flame"
> people that may not have as much knowledge of the subject as you.
> pathetic.
> 
> i suggest you get a life. you're all a little too smug for your own
> good.
> 
> oh, also, i guess i'm not cool because i don't have a witty quip at
> the end of my message, or use case sensitive words or end plural words
> with a string of "z's."
> 
> jack

amazing you took the time to alienate yourself from some of the sharpest 
minds in perl... talk about a waste of time...

-- 
Michael Budash


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

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


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