[13862] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1272 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 3 21:05:44 1999

Date: Wed, 3 Nov 1999 18:05:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941681120-v9-i1272@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 3 Nov 1999     Volume: 9 Number: 1272

Today's topics:
    Re: "Argument" I don't understand <aqumsieh@matrox.com>
    Re: -w <cassell@mail.cor.epa.gov>
        Broken Arrow <fheasley@chemistry.com>
    Re: comparing text with words <cassell@mail.cor.epa.gov>
    Re: core dump - perl, me or server? <aqumsieh@matrox.com>
        Creating Hashes? <shon@mad.scientist.com>
    Re: Creating Hashes? <marcel.grunauer@lovely.net>
    Re: Creating Hashes? (Michael Budash)
    Re: Creating Hashes? <rootbeer@redcat.com>
    Re: Creating Hashes? <cassell@mail.cor.epa.gov>
    Re: Determining Open Mode <aqumsieh@matrox.com>
    Re: Dos box when running perl CGIs <cassell@mail.cor.epa.gov>
    Re: Dos box when running perl CGIs <cassell@mail.cor.epa.gov>
    Re: Extract string <cassell@mail.cor.epa.gov>
    Re: FAQ 4.9: Why aren't my random numbers random? <cassell@mail.cor.epa.gov>
    Re: FAQ 8.45: How do I install a module from CPAN? <aqumsieh@matrox.com>
    Re: FAQ 8.45: How do I install a module from CPAN? (Guenther)
        File Access (Pathnames) <martin@mert.globalnet.co.uk>
    Re: File Access (Pathnames) <marcel.grunauer@lovely.net>
    Re: File Access (Pathnames) <rootbeer@redcat.com>
        Good answer! (Was: Help for listing directory contents) (Michael Budash)
    Re: HELP:Elements in an array have a space in front of  <cassell@mail.cor.epa.gov>
    Re: HELP:Elements in an array have a space in front of  <ehberry@uswest.com>
    Re: HELP:Elements in an array have a space in front of  <aqumsieh@matrox.com>
    Re: HELP:Elements in an array have a space in front of  <lr@hpl.hp.com>
    Re: Hex output help <cassell@mail.cor.epa.gov>
    Re: Hex output help <rick.delaney@home.com>
    Re: Hex output help <lr@hpl.hp.com>
    Re: How can I store/print a variable containing a DISPL <cassell@mail.cor.epa.gov>
        Inplace editing and safety <vobguy@yahoo.com>
    Re: Inplace editing and safety <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 3 Nov 1999 18:57:55 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: "Argument" I don't understand
Message-Id: <x3yu2n3ruv1.fsf@tigre.matrox.com>


kragen@dnaco.net (Kragen Sitaker) writes:
> In article <38205C28.31DF@ocg6.marine.usf.edu>,
> Patrick Smith  <patrick@ocg6.marine.usf.edu> wrote:

[snip]

> >#sorts array of test data
> >@srtedarray = sort{(split/''/,$a)[0]<=>(split/''/,$b)[0]}@data;
> 
> Here you're using a pattern consisting of two apostrophes for your
> field delimiter.  My guess is that you didn't mean to do that, because
> there are no apostrophes in your input data.
> 
> If you want to split on whitespace, use /\s+/ instead.

No. Use the magical ''. I guess this is what Patrick was trying to do,
but failed:

	split '' => $a;

'perldoc -f split' for more info (scroll down .. way down).

--Ala



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

Date: Wed, 03 Nov 1999 16:19:23 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: -w
Message-Id: <3820D10B.41AF6A24@mail.cor.epa.gov>

brian d foy wrote:
> 
> In article <7vq48q$d6l$2@info2.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:
[snip of Larry R's post]
> >Anyone who may legally possess firearms and anyone who might be
> >compelled to go fight a war certainly deserves the occasional beer or
> >seven.  Don't you know that half (nay, three-quarters) of the fun of
> >Perl people gatherings is getting sloshed together? :-)
> 
> the other quarter is obviously using firearms:
> 
>     http://sussex.pm.org/campcamel/index.html
> 
> a shotgun does quite a bit of damage to a Selena Sol book. :)

Not enough, if you ask me.

David, ducking...
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 3 Nov 1999 17:18:41 -0800
From: "Frank" <fheasley@chemistry.com>
Subject: Broken Arrow
Message-Id: <7vqmv8$64p$1@brokaw.wa.com>

perl neophyte: "What does an arrow operator do?"
perl insider <chuckle> "It dereferences a reference"
perl neophyte: "If I have a reference, why would I want to dereference it?
Wouldn't that make it go away?  How would making it go away help my program.
This doesn't make any sense."
perl insider: obviously you're not a C programmer
perl neophyte: "That's right.  I wanted to learn perl"
perl insider: "That's why we're insiders and you're an outsider...go learn
C++ and you'll know what we mean (nudge-nudge-wink-wink)"

Ah used de arry op'rator and dereference ain't dereference any more.

heheheh




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

Date: Wed, 03 Nov 1999 16:15:22 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: comparing text with words
Message-Id: <3820D01A.A94FF017@mail.cor.epa.gov>

Uri Guttman wrote:
> 
> >>>>> "AQ" == Ala Qumsieh <aqumsieh@matrox.com> writes:
> 
>   AQ> My question is why do people usually prefer tr/// over y///? I don't
>   AQ> see an answer to this in TFM. And I did RTFM .. several times.
> 
> other than for golf or obsfucation reasons, i (and i bet most others)
> find tr more mnemonic than y.
> 
> and its name is translation (regardless of what the current docs say).

And will stay that way.  At the time we had the big
translation/transliteration ligo-fest here, I got a nice
personal email from TomC that basically said:
    "I like it the way it is.  Larry likes it the
    way it is.  So there."

La plus sa change...

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 3 Nov 1999 18:48:33 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: core dump - perl, me or server?
Message-Id: <x3ywvrzrvam.fsf@tigre.matrox.com>


Richard H <rhardicr@mail.ford.com> writes:

> 
> Hi,
> I am unfamiliar with the reasons for core dumps but the following causes
> one on our Solaris box, the eval is used other places in my code and
> works fine, what am I missing? is it a Perl problem or a server issue?
> 
> 
> #!/usr/local/bin/perl -w
> use diagnostics;
> use strict;
> 
> &load;
> sub load {
>     eval('use Page');
> }
> print "end\n"; 

I can not reproduce your problem.

% perl -v
This is perl, version 5.005_03 built for sun4-solaris


What does the Page module look like?

--Ala



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

Date: Wed, 03 Nov 1999 23:30:58 GMT
From: Shon Stephens <shon@mad.scientist.com>
Subject: Creating Hashes?
Message-Id: <7vqgji$l96$1@nnrp1.deja.com>

 I want to read a multline file, each line containing comma separated
values. Then I want to take the 1st and 2nd fields (dumping the rest)
and put them into a hash with the 1st field being the key and second
being the value. (I think thats generally how hashes work?) So that
input lines like:

line1 1,2,3
line2 a,b,c

Would yield:

keys(%hash) = (1,a)
and
values(%hash) = (2,b)

--
Shon Stephens
UNIX Systems Administrator
shon@mad.scientist.com
"You want a piece of me?"


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 03 Nov 1999 23:54:11 GMT
From: Marcel Grunauer <marcel.grunauer@lovely.net>
Subject: Re: Creating Hashes?
Message-Id: <0tggOAqbh4LBXQriQa3xoAHD385u@4ax.com>

On Wed, 03 Nov 1999 23:30:58 GMT, Shon Stephens
<shon@mad.scientist.com> wrote:

>  I want to read a multline file, each line containing comma separated
> values. Then I want to take the 1st and 2nd fields (dumping the rest)
> and put them into a hash with the 1st field being the key and second
> being the value. (I think thats generally how hashes work?) So that
> input lines like:
> 
> line1 1,2,3
> line2 a,b,c
> 
> Would yield:
> 
> keys(%hash) = (1,a)
> and
> values(%hash) = (2,b)

#!/usr/bin/perl -w

use strict;
my %hash;

while (<DATA>) {
	my ($k,$v) = split /,/;
	$hash{$k} = $v;
}

print map { "$_ => $hash{$_}\n" } keys %hash;

__DATA__
1,2,3
a,b,c



-- 
Marcel, Perl Padawan
sub AUTOLOAD{$_=$AUTOLOAD;s;.*::;;;y;_; ;;print}&Just_Another_Perl_Hacker;


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

Date: Wed, 03 Nov 1999 16:00:58 -0800
From: mbudash@wcws.com (Michael Budash)
Subject: Re: Creating Hashes?
Message-Id: <mbudash-0311991600580001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>

In article <7vqgji$l96$1@nnrp1.deja.com>, Shon Stephens
<shon@mad.scientist.com> wrote:

>  I want to read a multline file, each line containing comma separated
> values. Then I want to take the 1st and 2nd fields (dumping the rest)
> and put them into a hash with the 1st field being the key and second
> being the value. (I think thats generally how hashes work?) So that
> input lines like:
> 
> line1 1,2,3
> line2 a,b,c
> 
> Would yield:
> 
> keys(%hash) = (1,a)
> and
> values(%hash) = (2,b)
> 

i'd lose at perl golf (!), but this works:

while (<YOURFILE>) {
 ($key, $value, $therest) = split(/,/);
 $hash{$key} = $value;
 }
-- 
Michael Budash ~~~~~~~~~~ mbudash@wcws.com


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

Date: Wed, 3 Nov 1999 16:29:17 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Creating Hashes?
Message-Id: <Pine.GSO.4.10.9911031628270.29670-100000@user2.teleport.com>

On Wed, 3 Nov 1999, Shon Stephens wrote:

>  I want to read a multline file, each line containing comma separated
> values. Then I want to take the 1st and 2nd fields (dumping the rest)
> and put them into a hash with the 1st field being the key and second
> being the value.

It sounds as if you want to use split(). If that's not where you're stuck,
show us how far you've gotten. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Nov 1999 16:55:55 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Creating Hashes?
Message-Id: <3820D99B.977765E8@mail.cor.epa.gov>

Shon Stephens wrote:
> 
>  I want to read a multline file, each line containing comma separated
> values. Then I want to take the 1st and 2nd fields (dumping the rest)
> and put them into a hash with the 1st field being the key and second
> being the value. (I think thats generally how hashes work?) So that
> input lines like:
> 
> line1 1,2,3
> line2 a,b,c
> 
> Would yield:
> 
> keys(%hash) = (1,a)
> and
> values(%hash) = (2,b)

Okay, here's a short program which illustrates one way to do this.
No claims that this is the fastest.

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

my %hash;

while (<DATA>) {
    $hash{$1} = $2 if /^([^,]+),([^,]+)/;
    }

map {print "$_ => $hash{$_}\n"} sort keys %hash;

__DATA__
1,2,3,4,5
a,b,c,d,e
foo,bar,baz,quux
alpha,beta,delta,gamma
hi,ho,hi,ho,its,off,to,work,we,go


And you get this output:

1 => 2
a => b
alpha => beta
foo => bar
hi => ho


David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 3 Nov 1999 19:09:38 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Determining Open Mode
Message-Id: <x3yr9i7rubh.fsf@tigre.matrox.com>


Jim Williams <james.p.williams@usahq.unitedspacealliance.com> writes:

> Yeah, I figured it was a silly thing to do.  I'm creating a module that
> represents a particular file format we use.  Such objects can be
> configured to either read or write the format, but not both.  The
> constructor accepts a filehandle, so I have to add another
> argument, 'r' or 'w', so I know if the object is being created for
> input or output. 

I guess this is a necessary piece of information since your module can
be used in more than one way; much like the open() function.

You can either do that, or you can pass to the constructor the name of
the file, and the mode of access to that file. Then you can create a
filehandle locally in your object. I would use the IO::File module for
that. Now, you have the filehandle and the mode of access.
  
>                  I want to keep using filehandles here to support both
> files and pipes without having to parse the file specifier myself.  I
> was looking for a way to eliminate the annoying open mode argument
> since it's redundant information I'm imposing on clients of the module.

From what you explain, I can't see how this information is
redundant. If your clients don't need to access the files themselves,
don't let them open() the files. Ask them for the filename, and the
mode of acces, and let the object do all the work. Like open(), you
can have a default mode, but I don't see why you are calling it
"redundant information".

> I suppose I could write two modules, one for input and the other for
> output.  Thanks for the kind reply.

I wouldn't do that myself. But, I might consider writing a parent
class, and a couple of child classes that inherit from the parent
class, and do their respective business.

HTH,
--Ala



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

Date: Wed, 03 Nov 1999 16:10:39 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Dos box when running perl CGIs
Message-Id: <3820CEFF.8AC7BDFF@mail.cor.epa.gov>

semiel@usa.net wrote:
> 
> Hi...
> I dont know if this is the right group to ask this question but i will
> give it a try:)
> 
> When running a perl cgi script in a browser (on the PC where perl is
> installed of course) there is a very brief dos box opening when running
> perl.exe.
> 
> The script works alright but i just wanted to know if there was a way
> to prevent a dos box from opening?

This sounds like the common problem seen when clicking on
Perl scripts even with no CGI components.  This has been
discussed on the Win32-Perl-Users mailing list, to which
you can subscribe by going to:

http://www.activestate.com/support/mailng_lists.htm

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 03 Nov 1999 16:12:02 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Dos box when running perl CGIs
Message-Id: <3820CF52.6D283E9C@mail.cor.epa.gov>

paul_rahe@cissc.canon.com wrote:
> 
> On Wed, 03 Nov 1999 17:24:32 GMT, semiel@usa.net wrote:
> 
> >When running a perl cgi script in a browser (on the PC where perl is
> >installed of course) there is a very brief dos box opening when running
> >perl.exe.
> The interpreter does not need to be installed in the client for this
> task, it needs to be running on the web server.
> >
> >The script works alright but i just wanted to know if there was a way
> >to prevent a dos box from opening?
> Are you running a web server on your client PC?  It sounds like you
> may have a web server configuration issue.
> 
> You might want to try asking this question in
> comp.infosystems.www.authoring.cgi.

Actually, this one may be a real Perl question, albeit a
win32/Perl question.  c.i.w.a.g. may not be a good place
to ask this time.  But YMMV.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 03 Nov 1999 16:01:46 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Extract string
Message-Id: <3820CCEA.37A8EE39@mail.cor.epa.gov>

Kragen Sitaker wrote:
> 
> In article <381E5793.C249CE1E@inprise.com>,
> Adrian Chin  <Achin@inprise.com> wrote:
> >vol1/extract/inst/sum.C:1:2:3
> >vol2/extract/algo.h:2:3:4
> >vol3/extr/rol/rojak/bunga/fungi.sh:1:2:3
> >
> >in a file call file.txt.  How do I extract the colored string out to a
> >variable in per
> 
> Which string is colored?  And what is "per"?

Oh, so you're colorblind too.  You and Larry should really
have that checked.  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 03 Nov 1999 16:00:44 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
To: Tom and Gnat <perlfaq-suggestions@perl.com>
Subject: Re: FAQ 4.9: Why aren't my random numbers random?
Message-Id: <3820CCAC.29BB0577@mail.cor.epa.gov>

[email copy to perlfaq-suggestions]

Tom Christiansen wrote:
> 
> (This excerpt from perlfaq4 - Data Manipulation
>     ($Revision: 1.49 $, $Date: 1999/05/23 20:37:49 $)
> part of the standard set of documentation included with every
> valid Perl distribution, like the one on your system.
> See also http://language.perl.com/newdocs/pod/perlfaq4.html
> if your negligent system adminstrator has been remiss in his duties.)
> 
>   Why aren't my random numbers random?
> 
>     If you're using a version of Perl before 5.004, you must call
>     `srand' once at the start of your program to seed the random number
>     generator. 5.004 and later automatically call `srand' at the
>     beginning. Don't call `srand' more than once--you make your numbers
>     less random, rather than more.
> 
>     Computers are good at being predictable and bad at being random
>     (despite appearances caused by bugs in your programs :-).
>     http://www.perl.com/CPAN/doc/FMTEYEWTK/random, courtesy of Tom
>     Phoenix, talks more about this.. John von Neumann said, ``Anyone
>     who attempts to generate random numbers by deterministic means is,
>     of course, living in a state of sin.''

      If your random numbers seem to repeat in a short cycle,
      or do not cover the range of numbers you tried to produce,
      you may have compiled Perl with the wrong value of randbits.

[snip of remainder]

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 3 Nov 1999 19:01:25 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: FAQ 8.45: How do I install a module from CPAN?
Message-Id: <x3yso2nrup6.fsf@tigre.matrox.com>


nottrue@nomail.nonet (Guenther) writes:

> Can any say me pls how to install modules on win98 and activeperl?

Use Activestate's ppm (Perl Package Manager).

http://www.activestate.com/activeperl/docs/Perl-Win32/perlwin32faq11.html

HTH,
--Ala



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

Date: Thu, 04 Nov 1999 01:55:53 GMT
From: nottrue@nomail.nonet (Guenther)
Subject: Re: FAQ 8.45: How do I install a module from CPAN?
Message-Id: <3822d2d6.26865025@news>

On Wed, 3 Nov 1999 11:14:51 -0800, Tom Phoenix <rootbeer@redcat.com>
wrote:

Thx all for the help.
I installed some modules with the ppm manager but i had a problem with
one:
GDBM_File
If i start a script with the module inside it tels me:
Can't locate auto/GDBM_File/autosplit.ix in @INC (@INC
contains:D:/Perl/lib D:/Perl/site/lib .) at D:/Perl/lib/AutoLoader.pm
line 127. at D:/Perl/site/lib/GDBM_File.pm line 48
also a manual try with nmake ... had no success

>On Wed, 3 Nov 1999, Guenther wrote:
>
>> Can any say me pls how to install modules on win98 and activeperl?
>
>See the Perl-for-Win32 FAQ.
>
>    http://www.activestate.com/ActivePerl/docs/Perl-Win32/perlwin32faq.html
>
>Cheers!



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

Date: Wed, 3 Nov 1999 23:47:09 -0000
From: "Martin Elliott" <martin@mert.globalnet.co.uk>
Subject: File Access (Pathnames)
Message-Id: <7vqhn5$nk1$1@gxsn.com>

I have my first script up and running, hoorah!

It basically manipulates flat file databases, which up until now I have had
to place in my cgi-bin. Now, after testing, I would like to move the files
to another location, but there's something wrong, this is how I try to do
it:

open FILE "> /path1/path2/path3/file.txt"

This code doeswn't seem to work, is there something I have missed?

Thanks,

Martin




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

Date: Wed, 03 Nov 1999 23:56:33 GMT
From: Marcel Grunauer <marcel.grunauer@lovely.net>
Subject: Re: File Access (Pathnames)
Message-Id: <CNkgOB2N=IOCBD3YbN97TVW2WTbN@4ax.com>

On Wed, 3 Nov 1999 23:47:09 -0000, "Martin Elliott"
<martin@mert.globalnet.co.uk> wrote:

> It basically manipulates flat file databases, which up until now I have had
> to place in my cgi-bin. Now, after testing, I would like to move the files
> to another location, but there's something wrong, this is how I try to do
> it:
> 
> open FILE "> /path1/path2/path3/file.txt"
> 
> This code doeswn't seem to work, is there something I have missed?

	perldoc -f open

and take a good look at the syntax.

Also remember to always check the return values of system calls:

	open(FILE,">$file") || die "can't create $file: $!"

And 'use strict' !

And use '-w' !

Save you it can!


-- 
Marcel, Perl Padawan
sub AUTOLOAD{$_=$AUTOLOAD;s;.*::;;;y;_; ;;print}&Just_Another_Perl_Hacker;


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

Date: Wed, 3 Nov 1999 16:30:40 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: File Access (Pathnames)
Message-Id: <Pine.GSO.4.10.9911031629320.29670-100000@user2.teleport.com>

On Wed, 3 Nov 1999, Martin Elliott wrote:

> open FILE "> /path1/path2/path3/file.txt"

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Nov 1999 15:32:16 -0800
From: mbudash@wcws.com (Michael Budash)
Subject: Good answer! (Was: Help for listing directory contents)
Message-Id: <mbudash-0311991532160001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>

In article <Pine.GSO.4.10.9911031458450.29670-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:

> On Wed, 3 Nov 1999, ScrO wrote:
> 
> > I am looking for a script 
> 
> If you're wishing merely to _find_ (as opposed to write) programs,
> this newsgroup may not be the best resource for you. There are many
> freeware and shareware archives which you can find by searching Yahoo
> or a similar service. 
> 
> If you want to write one, look for readdir and friends in the perlfunc
> manpage.
> 
> Hope this helps!
> 

folks. i just gotta say, tom always seems to answer questions in a nice
lets-not-just-give-the-man-a-fish style, even when a lot of us would flame
the poster. some people may find that 'too nice', but i think it's
right-on (oops, 60's flashback!)

tom, you're ok in my book (for whatever good or bad that does you!).
-- 
Michael Budash ~~~~~~~~~~ mbudash@wcws.com


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

Date: Wed, 03 Nov 1999 16:33:40 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: HELP:Elements in an array have a space in front of them
Message-Id: <3820D464.FC3FCBE9@mail.cor.epa.gov>

Tom Phoenix wrote:
> 
> On Wed, 3 Nov 1999, Ed Berry wrote:
> 
> > The first element is correct but all the following elements have a space
> > in the first character.  What am I doing wrong?
> 
> Look at your print statement. You didn't include it in your message, and I
> couldn't read it with the Usenet::ESP module. Do you have double quote
> marks around an array whose elements contain newline characters?

I think you meant the PSI::ESP module.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 03 Nov 1999 17:47:40 -0700
From: Ed Berry <ehberry@uswest.com>
To: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: HELP:Elements in an array have a space in front of them
Message-Id: <3820D7AC.8F8571DD@uswest.com>

The double quotes around the array was the problem!!  I removed them and
it works great!  Thanks!

Tom Phoenix wrote:
> 
> On Wed, 3 Nov 1999, Ed Berry wrote:
> 
> > The first element is correct but all the following elements have a space
> > in the first character.  What am I doing wrong?
> 
> Look at your print statement. You didn't include it in your message, and I
> couldn't read it with the Usenet::ESP module. Do you have double quote
> marks around an array whose elements contain newline characters?
> 
> Cheers!
> 
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/


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

Date: Wed, 3 Nov 1999 19:15:50 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: HELP:Elements in an array have a space in front of them
Message-Id: <x3ypuxrru15.fsf@tigre.matrox.com>


kragen@dnaco.net (Kragen Sitaker) writes:
> In article <3820A259.4B8903C9@uswest.com>,
> Ed Berry  <ehberry@uswest.com> wrote:
> >
> >The first element is correct but all the following elements have a space
> >in the first character.  What am I doing wrong?
> 
> My guess:  you're doing print "@weather", which prints array elements
> separated by spaces.  The spaces aren't really in the array elements,
> but are inserted by interpolating the array into a string.

Just to elaborate a bit:

You will usually get spaces between your array elements unless of
course you mess with $" whose default value is a single space
character. The value of this variable gets inserted between array
elements when an array is interpolated inside double quotes.

Note that:
	print "@array";

is different from:
	print @array;

The first sticks $" (which is a space by default) between the
elements. The second sticks a $, (which is an empty string by default)
between the elements.

> But hey, I could be wrong.

Me too :)

--Ala



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

Date: Wed, 3 Nov 1999 17:51:20 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: HELP:Elements in an array have a space in front of them
Message-Id: <MPG.128a8677e246a9ed98a19e@nntp.hpl.hp.com>

In article <x3ypuxrru15.fsf@tigre.matrox.com> on Wed, 3 Nov 1999 
19:15:50 -0500 , Ala Qumsieh <aqumsieh@matrox.com> says...
> kragen@dnaco.net (Kragen Sitaker) writes:
> > In article <3820A259.4B8903C9@uswest.com>,
> > Ed Berry  <ehberry@uswest.com> wrote:
> > >The first element is correct but all the following elements have a space
> > >in the first character.  What am I doing wrong?
> > 
> > My guess:  you're doing print "@weather", which prints array elements
> > separated by spaces.  The spaces aren't really in the array elements,
> > but are inserted by interpolating the array into a string.
> 
> Just to elaborate a bit:
> 
> You will usually get spaces between your array elements unless of
> course you mess with $" whose default value is a single space
> character. The value of this variable gets inserted between array
> elements when an array is interpolated inside double quotes.

 ...

> > But hey, I could be wrong.
> 
> Me too :)

But not perlfaq5: "Why do I get weird spaces when I print an array of 
lines?"

Even Tom Phoenix answered this one directly without pointing at the FAQ!

Whazzup, guys?  In the fish business instead of the fishing business?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 03 Nov 1999 16:25:12 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Hex output help
Message-Id: <3820D268.46FA1999@mail.cor.epa.gov>

Alan Curry wrote:
> 
> In article <7vq4s9$bv4$1@nnrp1.deja.com>,  <nite_eagle@hotmail.com> wrote:
> >I tried printf "0x%x" , $data; but that just output 0x0
> >How do I get perl to output what DBI gave me as a hex string?
> 
> for (split //, $yourvar) {
>   printf "%02x", ord $_;

Or even:

map {printf "%02x", ord $_} split //, $yourvar;

which yields the same output.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 04 Nov 1999 00:41:10 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Hex output help
Message-Id: <3820D638.1EE3A1C1@home.com>

[posted & mailed]

David Cassell wrote:
> 
> Or even:
> 
> map {printf "%02x", ord $_} split //, $yourvar;
> 
> which yields the same output.

Allow me to resurrect this little gem from Uri who wrote:
> 
> >>>>> "RD" == Rick Delaney <rick.delaney@home.com> writes:
> 
>   RD> OW:
>   RD>     printf '%.2x ' => ord for split //, $string;
> 
> why make your cpu sweat and my eyeballs roll?
> 
> print unpack 'H*', $string ;

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Wed, 3 Nov 1999 16:58:04 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Hex output help
Message-Id: <MPG.128a79f4e0b75a7798a19d@nntp.hpl.hp.com>

In article <3820D268.46FA1999@mail.cor.epa.gov> on Wed, 03 Nov 1999 
16:25:12 -0800, David Cassell <cassell@mail.cor.epa.gov> says...
> Alan Curry wrote:
> > In article <7vq4s9$bv4$1@nnrp1.deja.com>,  <nite_eagle@hotmail.com> wrote:
> > >I tried printf "0x%x" , $data; but that just output 0x0
> > >How do I get perl to output what DBI gave me as a hex string?
> > 
> > for (split //, $yourvar) {
> >   printf "%02x", ord $_;
> 
> Or even:
> 
> map {printf "%02x", ord $_} split //, $yourvar;
> 
> which yields the same output.

  Or even:
  
  print unpack 'H*' => $yourvar;
  
  which yields the same output.

(A whole lot faster, I would expect.  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 03 Nov 1999 16:05:21 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How can I store/print a variable containing a DISPLAY IP address?
Message-Id: <3820CDC1.200A3FD0@mail.cor.epa.gov>

[Jeopardy-style reply moved to the correct place, as shown below]

Maurice Maltbia wrote:
[attribution to Tom Phoenix cut off by Maurice]
> >>       $IP_address = '111.222.333.64;
> >
> >Do you really want just one quote mark there? Cheers!
>
> No, but that still doesn't solve my problem.

It doesn't?  Have you tried putting the needed quote in that
line, adding -w to your shebang line, and re-running the code?
What did you get?  Even with the PSI::ESP module, I can't help
you without some indication of what's going wrong for you.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 03 Nov 1999 17:24:04 -0500
From: WoV <vobguy@yahoo.com>
Subject: Inplace editing and safety
Message-Id: <3820B604.D7064517@yahoo.com>

I searched deja and didn't see anything on point to this topic so 
hopefully I won't be flamed too badly...

How safe is it to use perl to do inplace editing of a file, assuming 
that you _are_ using the a backup file (i.e. pi.bak.. ).

Are there any known cases where the file could be emptied in case
of catastrophic failures like power outage, network going down, etc. at 
the wrong time?  (yes, I know in general catastrophic failures might 
corruption from other sources, I want to know am I increasing my
chances that the corruption will happen if I am doing an inplace edit 
when a failure occurs.)

Along the same lines, what hints do you have for signal handling in a 
script where inplace editing may occur?

Regards, 

Al

-- 
"An expert is a man who has made all the mistakes which 
can be made, in a narrow field."   - Niels Bohr
"If at first you don't succeed, try, try again. Then give
 up. No use being a damned fool about it." - W.C. Fields


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

Date: 03 Nov 1999 20:30:03 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Inplace editing and safety
Message-Id: <x73dun82n8.fsf@home.sysarch.com>

>>>>> "W" == WoV  <vobguy@yahoo.com> writes:

  W> I searched deja and didn't see anything on point to this topic so 
  W> hopefully I won't be flamed too badly...

not if you actually did the search. hmmm, let me check their logs, looks
like you did.

  W> How safe is it to use perl to do inplace editing of a file, assuming 
  W> that you _are_ using the a backup file (i.e. pi.bak.. ).

  W> Are there any known cases where the file could be emptied in case
  W> of catastrophic failures like power outage, network going down, etc. at 
  W> the wrong time?  (yes, I know in general catastrophic failures might 
  W> corruption from other sources, I want to know am I increasing my
  W> chances that the corruption will happen if I am doing an inplace edit 
  W> when a failure occurs.)

this is a good question. perl first renames the file to the backup name
and then opens that for input. it then opens the original name for
output. rename is atomic in all decent os's. so that means you shouldn't
ever lose the original contents but you may not know which file it is in
depending on when the act of god hit.

  W> Along the same lines, what hints do you have for signal handling in a 
  W> script where inplace editing may occur?

most of the time -i is used with -n or -p, so you have an implied
loop. best thing is to have the signal handler just set a global flag
and check that in the main code and exit or close the file or
whatever. then you can control the behavior yourself. checking for eof
will allow you do do this in between files as well.

something like (untested): 

#!/bin/perl -pi.bak

BEGIN{ $SIG{ INT } = sub { $sig_int++ } ;

close( ARGVOUT ) && exit if $sig_int && eof) ;

blah edit blah 


note use of ARGVOUT which is the output handle used by -i. read perlrun
and the section on -i for more on it. i just did and learned about the *
in the extension feature which is new for 5.005 it seems.

uri


-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1272
**************************************


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