[17154] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4566 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 10 00:05:26 2000

Date: Mon, 9 Oct 2000 21: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)
Message-Id: <971150709-v9-i4566@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 9 Oct 2000     Volume: 9 Number: 4566

Today's topics:
    Re: Checking for existence of file <bwalton@rochester.rr.com>
        chown (Maggert)
    Re: chown <tony_curtis32@yahoo.com>
    Re: chown (Maggert)
    Re: chown <elaine@chaos.wustl.edu>
    Re: chown (Maggert)
        comparing arrays (dionysus)
    Re: comparing arrays (dionysus)
    Re: DBI arrayref <bwalton@rochester.rr.com>
    Re: Different Ways to Obtain a Client`s IP ? <bart.lateur@skynet.be>
    Re: extract a segment of strings in a text <ren.maddox@tivoli.com>
        List as keys for hash <ipetts@ozemail.com.au>
    Re: List as keys for hash (Martien Verbruggen)
    Re: List as keys for hash <bwalton@rochester.rr.com>
    Re: need blanks at end of format line <ren.maddox@tivoli.com>
    Re: need blanks at end of format line <rick.delaney@home.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Oct 2000 01:07:00 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Checking for existence of file
Message-Id: <39E26C8F.23396B92@rochester.rr.com>

Geoff Soper wrote:
> 
> In article <Pine.GHP.4.21.0010081839360.10958-100000@hpplus03.cern.ch>,
>    Alan J. Flavell <flavell@mail.cern.ch> wrote:
> > On Sun, 8 Oct 2000, Geoff Soper wrote:
> 
> > > What is the '-e' and what does it do?
> 
> > What is documentation?
> 
> I had looked before asking and couldn't see how to look up the meaning of
> a given function.
> As a non-programmer until extemely recently, I'm still figuring things out.
> Thanks.

Geoff, use:

    perldoc perldoc

at your operating system prompt to find out all about one way of
accessing Perl's on-line documentation.  And please do check it
carefully before posting, as you will get either terse responses or no
responses if you make a habit of asking questions thoroughly covered in
the docs or faqs.  In the case of -e, your question was probably legit,
as no one but a shell programmer would think of -e as a file existence
test operator.  But don't ask stuff like "how do I find the length of a
string" or "how do I sort xxx by yyy" :-).

> 
> --
> Geoff Soper
> g.soper@soundhouse.co.uk
> Take a look at the Soundhouse page http://www.soundhouse.co.uk/
-- 
Bob Walton


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

Date: Tue, 10 Oct 2000 02:16:31 GMT
From: mag@ionet.net (Maggert)
Subject: chown
Message-Id: <39e27a82.246768884@news.ionet.net>

I have a script running on a DEC Alpha thats configured not to let
"nobody" create directories outside of the cgi-bin. Is it possible to
chown the process and create the directory? 
I know from the docs that chown doesn't always work on tight systems.
I am still just a bit confused though as the docs are pretty vague.
I'll be doing some experimenting, but if anyone has some insight I
would appreciate it.

from the docs;
On most systems, you are not allowed to change the ownership of the
file unless you're the superuser, although you should be able to
change the group to any of your secondary groups. On insecure systems,
these restrictions may be relaxed, but this is not a portable
assumption. 

Of course this assumes I want to change ownership of a file. What I
need to do is change ownership of the process!


MP


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

Date: 09 Oct 2000 21:09:43 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: chown
Message-Id: <87snq5e9aw.fsf@limey.hpcc.uh.edu>

>> On Tue, 10 Oct 2000 02:16:31 GMT,
>> mag@ionet.net (Maggert) said:

> I have a script running on a DEC Alpha thats configured
> not to let "nobody" create directories outside of the
> cgi-bin. Is it possible to chown the process and create
> the directory?  I know from the docs that chown doesn't
> always work on tight systems.  I am still just a bit
> confused though as the docs are pretty vague.  I'll be
> doing some experimenting, but if anyone has some insight
> I would appreciate it.

> from the docs; On most systems, you are not allowed to
> change the ownership of the file unless you're the
> superuser, although you should be able to change the
> group to any of your secondary groups. On insecure
> systems, these restrictions may be relaxed, but this is
> not a portable assumption.

> Of course this assumes I want to change ownership of a
> file. What I need to do is change ownership of the
> process!

Read your article carefully.  Can you see any perl
relevance?  'Cause I can't.

I'd post to a group appropriate to your OS and/or for your
webserver if I were you.

hth
t
-- 
Namaste!
And an "oogabooga" to you too!
                                         -- Homer Simpson


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

Date: Tue, 10 Oct 2000 02:42:06 GMT
From: mag@ionet.net (Maggert)
Subject: Re: chown
Message-Id: <39e2813e.248492453@news.ionet.net>

On 09 Oct 2000 21:09:43 -0500, Tony Curtis <tony_curtis32@yahoo.com>
wrote:


>Read your article carefully.  Can you see any perl
>relevance?  'Cause I can't.
>
	Yes of course there is relevance! chown is a perl function. I
just want to know if this function can be used so I can create a
directory.
	I've already assumed not and am looking at using Net::FTP to
create the directory instead. I don't own the server and don't put too
much hope in the admin changing server configuration!!
	

MP


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

Date: Tue, 10 Oct 2000 02:47:52 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: chown
Message-Id: <B607FB98.7BF5%elaine@chaos.wustl.edu>

in article 39e27a82.246768884@news.ionet.net, Maggert at mag@ionet.net
quoth:
> Of course this assumes I want to change ownership of a file. What I
> need to do is change ownership of the process!

Well, if you dont' want to CHange OWNership then what are you doing with
chown? What  you are looking for is suid where you change the euid/egid to
something that can do what you need. However, if this is a security
sensitive shop then suidperl is probably not installed nor is the web server
configured to allow for it.

http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlsec.html may prove to be
helpful.

e.




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

Date: Tue, 10 Oct 2000 03:37:18 GMT
From: mag@ionet.net (Maggert)
Subject: Re: chown
Message-Id: <39e28e19.251783114@news.ionet.net>

On Tue, 10 Oct 2000 02:47:52 GMT, Elaine Ashton
<elaine@chaos.wustl.edu> wrote:

>in article 39e27a82.246768884@news.ionet.net, Maggert at mag@ionet.net
>quoth:
>> Of course this assumes I want to change ownership of a file. What I
>> need to do is change ownership of the process!
>
>Well, if you dont' want to CHange OWNership then what are you doing with
>chown? What  you are looking for is suid where you change the euid/egid to
>something that can do what you need. However, if this is a security
>sensitive shop then suidperl is probably not installed nor is the web server
>configured to allow for it.
>
>http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlsec.html may prove to be
>helpful.
>

	Thanks! I figured chown wasn't what I really needed, but I do
appreciate the answer. I guess it's back to the old grind stone to
figue out an alternative. Net::FTP looks to be a good and safe bet
right now.

MP


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

Date: Tue, 10 Oct 2000 04:44:09 GMT
From: dionysus39@hotmail.com (dionysus)
Subject: comparing arrays
Message-Id: <39e29e1d.68976846@nntp.unsw.edu.au>

I have two arrays, and wish to get a list of all strings in the second
array that are not also in the first array. I understand that I could
write everything out in (very)longhand, but there surely should be
some simple perl set operations like this, shouldn't there? Any and
all advice much appreciated.

-dionysus

------------------------------------------------------------
"One World, one Web, one Program" - Microsoft promotional ad
"Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .


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

Date: Tue, 10 Oct 2000 04:45:35 GMT
From: dionysus39@hotmail.com (dionysus)
Subject: Re: comparing arrays
Message-Id: <39e29eb6.69130298@nntp.unsw.edu.au>

p.s. before anyone asks, yes I have spent the requisite time searching
the perl man pages, but haven't come up with anything useful :-<


On Tue, 10 Oct 2000 04:44:09 GMT, dionysus39@hotmail.com (dionysus)
wrote:

>I have two arrays, and wish to get a list of all strings in the second
>array that are not also in the first array. I understand that I could
>write everything out in (very)longhand, but there surely should be
>some simple perl set operations like this, shouldn't there? Any and
>all advice much appreciated.
>
>-dionysus
>
>------------------------------------------------------------
>"One World, one Web, one Program" - Microsoft promotional ad
>"Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .


------------------------------------------------------------
"One World, one Web, one Program" - Microsoft promotional ad
"Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .


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

Date: Tue, 10 Oct 2000 01:50:01 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: DBI arrayref
Message-Id: <39E276A5.4ADE2504@rochester.rr.com>

at wrote:
> 
> I am using the following piece of CGI script to place elements from a
> MySQL database into a scrolling listbox.  I keep getting values like
> ARRAY (0x822609c).  I am assuming that this is the reference to the
> array element instead of the element itself.  I have tried some
> suggestions found in some books about dereferencing, but to no avail.
> This appears to be the combination that works the best, as it returns
> the proper number of values, instead of a single value.  I can use a
> straight print function in the while loop and get the data properly,
> so the connection is working fine.  Thanks for anyone who can help.
> 
> while ( $array_ref = $sth->fetchrow_arrayref )
> {
>      push @ary, [ @$array_ref ];

Hmmm...you are dereferencing an array reference ($array_ref), then
making an array of it (@), then making an array reference to an
anonymous array ([...]), then pushing that onto an array.  Pretty
convoluted.  You could get the same thing with:

       push @ary,$array_ref;

It does look like a reasonable approach, as you end up with an array of
array references, each of the latter arrays containing a row of your
database.  You could have done pretty much the same thing, though, with:

       $a_ref=$dbh->selectall_arrayref("SQL statement...");

which returns a reference to an array of references to arrays that
contain the rows of your query.  Then you don't have to fuss with the
while loop, prepare, and all.

> }
> 
> print scrolling_list    (-name     =>   "category",
>                          -value    =>   [@ary],

I am guessing your scrolling_list function maybe is from CGI.pm??  But
you are passing it an array reference to an anonymous array, the
elements of which are the elements of @ary.  Again, pretty convoluted. 
Simpler would be:

     -values => \@ary,

(yeah, it isn't much simpler to write down, but the internals of what
happens with [@ary] are much more complicated and time-consuming:  Perl
makes an anonymous copy of your array, and returns a reference to that. 
Of course, sometimes that can be good, like if you want to assure that
the routine you are calling cannot possibly modify the original array
:-).

Then there is the question of whether that is what you really want.  I
see the -values (not -value as you stated) argument is supposed to be an
array reference to an array of strings destined for your scrolling
list.  But you are supplying a reference to an array of array
references, each of the latter which holds a row of your database.  That
isn't what scrolling_list is expecting, which explains your "ARRAY
(0x822609c)" values (that's what you get when you treat an array
reference as a string).  

You will have to write some additional code to build an array of the
strings you want in your scrolling list, and then pass scrolling_list a
reference to that array.  Take it a step at a time:  hand-generate an
array and pass a reference to it to scrolling_list, and see if you get a
proper scrolling list with the contents you specified.  Then add code to
populate that array from your database.  Also, please read and master:

   perldoc perldata
   perldoc perlreftut
   perldoc perlref

HTH.
>                          -size  =>      8,
>                          -multiple =>   1,
>                          -override =>   1);
-- 
Bob Walton


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

Date: Tue, 10 Oct 2000 02:13:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Different Ways to Obtain a Client`s IP ?
Message-Id: <anu4us0p8cgsm6s4mi03l4lisgdolkiav0@4ax.com>

Philip Lancefield wrote:

>For security reasons it is
>important that I obtain the real IP address of the person. 

You've never heard of PPP?

In case that is not familiar: this is a dynamic protocol, where every
time you log on to the Internet, you get a (likely) different temporary
IP address, from a pool that the ISP has available for this purpose. So
the ISP can service a lot more people than he has IP adresses for. But
not all at the same time.

-- 
	Bart.


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

Date: 09 Oct 2000 18:12:05 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: extract a segment of strings in a text
Message-Id: <m31yxpa9tm.fsf@dhcp11-177.support.tivoli.com>

DT <dsa@dassda.com> writes:

> Hi,
> Can someone tell me how to extact, segment of a string that enclosed by 
> tags. Like:
> 
> whatever, whatever, whatever, <tag>I want this<tag> whatever, whatever, 
> whatever,whatever, whatever, whatever,whatever, whatever, whatever,<tag>I 
> want this 111<tag> ,whatever, whatever <tag>I want this 222<tag> 
> whatever, whatever
> 
> the end result I want is: I want this, I want this 111, I want this 222

Be forewarned: this can get very complicated if tags can be nested, or
if the tag characters can appear inside quotes or [lots of other
things].  Depending on the particular data format, there are better
ways to handle this sort of thing.  For example, if the data is HTML,
then the HTML::Parser module is the correct tool.

That being said, this might be what you want:

@tags = /<tag>(.*?)<tag>/sg;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 10 Oct 2000 00:58:42 GMT
From: Ian Petts <ipetts@ozemail.com.au>
Subject: List as keys for hash
Message-Id: <8rtpjv$1l$1@nnrp1.deja.com>

I have a semi-colon seperated list that I need to re-arrange the field
order on. The order of the fields differs from file to file, and I need
to change them to a pre-determined order. The order of the file can be
determined from the first line. Take the following file for example:

	one;two;five;four;three
	1;10Oct2000;bbbbb;aaaaa;12:00:00
	2;10Oct2000;sxsxd;cassc;12:01:00
	3;10Oct2000;sfgsf;aaeee;12:02:30

I need to re-arrange all fields in the order one, two, three, four,
five.

With my rather limited Perl experience, I have come up with the
following:

#!/usr/bin/perl -w

use strict;
use diagnostics;

my $i;
my $x;
my $line;
my @record;
my %entry;
my @goodnames = qw(one two three four five);

$line = <STDIN>;
chomp($line);

for ($i=0; $i <= $#goodnames; $i++) {
  print "$goodnames[$i]";
  print ";" unless ($i == $#goodnames);
}
print "\n";

my @badnames = split(/;/, $line);

while ($line = <STDIN>) {
  chomp($line);
  @record = split(/;/, $line);
  $x = 0;
  foreach $i (@badnames) {
    $entry{$i} = $record[$x];
    $x++;
  }
   for ($i=0; $i <= $#goodnames; $i++) {
     print $entry{$goodnames[$i]} unless undef($entry{$goodnames[$i]});
     print ";" unless ($i == $#goodnames);
   }
  print "\n";
}


Running the program produces the following:

# cat filename | ./program.pl

one;two;three;four;five
Use of uninitialized value in print at ./program.pl line 33, <STDIN>
line 2 (#1)

    (W uninitialized) An undefined value was used as if it were already
defined.  It was
    interpreted as a "" or a 0, but maybe it was a mistake.  To suppress
this
    warning assign a defined value to your variables.

;;;;
Use of uninitialized value in print at ./program.pl line 33, <STDIN>
line 3 (#1)
;;;;
Use of uninitialized value in print at ./program.pl line 33, <STDIN>
line 4 (#1)
;;;;


Can someone please tell me where I have gone wrong and what I might do
to solve the problem. I am still coming to terms with many of the
concepts of perl and pointers to the relevant page(s) in the Llama or
Camel books would also be welcome.

Thanks,
Ian.


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


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

Date: Tue, 10 Oct 2000 01:55:11 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: List as keys for hash
Message-Id: <slrn8u4tnj.2ce.mgjv@verbruggen.comdyn.com.au>

On Tue, 10 Oct 2000 00:58:42 GMT,
	Ian Petts <ipetts@ozemail.com.au> wrote:
> I have a semi-colon seperated list that I need to re-arrange the field
> order on. The order of the fields differs from file to file, and I need
> to change them to a pre-determined order. The order of the file can be
> determined from the first line. Take the following file for example:
> 
> 	one;two;five;four;three

Ugh! Why not 

1;2;5;4;3

?? Now you need to 'parse' the strings to get real numbers.

We'll just assume that you never have more than 1 to 9.

> 	1;10Oct2000;bbbbb;aaaaa;12:00:00
> 	2;10Oct2000;sxsxd;cassc;12:01:00
> 	3;10Oct2000;sfgsf;aaeee;12:02:30
> 
> I need to re-arrange all fields in the order one, two, three, four,
> five.
> 
> With my rather limited Perl experience, I have come up with the
> following:

Not too bad. you use strict and -w. Very good starting point :)

> #!/usr/bin/perl -w
> 
> use strict;
> use diagnostics;
> 
> my $i;
> my $x;
> my $line;
> my @record;
> my %entry;

You are using strict, but you might as well not. You are lexically
scoping almost all your variables to the whole file. You should scope
them to the smallest enclosing block that uses them. These five should
all be scoped to the loop below.

> my @goodnames = qw(one two three four five);
> 
> $line = <STDIN>;
> chomp($line);
> 
> for ($i=0; $i <= $#goodnames; $i++) {
>   print "$goodnames[$i]";
>   print ";" unless ($i == $#goodnames);
> }
> print "\n";

All that can be done with something like:

print "@goodnames\n";

or if you must have the semicolons:

print join(';', @goodnames), "\n";

> my @badnames = split(/;/, $line);

You should put this right below the chomp up there. It's good practice
to keep code that belongs together in close proximity.

> while ($line = <STDIN>) {
>   chomp($line);
>   @record = split(/;/, $line);
>   $x = 0;
>   foreach $i (@badnames) {
>     $entry{$i} = $record[$x];
>     $x++;
>   }

You're looping for each line? Quite expensive. Now you have a hash
with the keys being the fields of the first line, and the values being
the fields of the current line. A shorter way would have been:

@entry{@badnames} = @record;

Read about the tremendously useful array and hash slices in the
perldata documentation.

# perldoc perldata

>    for ($i=0; $i <= $#goodnames; $i++) {
>      print $entry{$goodnames[$i]} unless undef($entry{$goodnames[$i]});
>      print ";" unless ($i == $#goodnames);
>    }

undef($entry{$goodnames[$i]})) undefined that variable. You probably
wanted 'if defined $var'.

# perldoc -f undef
# perldoc -f defined

If you fix that problem, your program will run fine. However, see
later.

Something like

print join(';', @entry{@goodnames}), "\n";

will do the job in one line.

>   print "\n";
> }

GenerallY: you use quite a few constructions that are quite unperlish.
Perl has some constructions that make working with arrays and hashes a
lot easier, and more readable, once you're used to them.

I'll see if I can come up with something that's both short and easily
understandable, and which, like my comments above, makes heavy use of
array and hash slices:

The first thing to do is to parse that first line, and to create an
array with numbers, instead of those strings. That array can (almost)
be used later in an array slice to reorder the other lines. Once you
have this array, almost all work is done.
Assuming that you only ever have to parse numbers between one and
nine, a hash slice is probably the easiest way to do this. Here's the
program, with some comments.

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

# Define mappings from string digits to numbers.
my %digits;
@digits{qw{one two three four five six seven eight nine}} = 1..9;

# Read the first line
# Split the line on /;/, and map the strings to numbers
# Make sure the numbers are array offsets (0-based)
chomp(my $order = <DATA>);
my @order = map { $digits{$_} - 1 } split /;/, $order;

# Read the other lines
while (my $line = <DATA>)
{
    chomp $line;

    # Split the line, reorder the fields, and join them again
    my @fields = split /;/, $line;
    @fields = @fields[@order];
    print join(';', @fields), "\n";

    # To do it all in one line, without a temporary array
    #print join(';', (split /;/, $line)[@order]), "\n";
}

__DATA__
one;two;five;four;three
1;10Oct2000;bbbbb;aaaaa;12:00:00
2;10Oct2000;sxsxd;cassc;12:01:00
3;10Oct2000;sfgsf;aaeee;12:02:30

This program assumes that you never have more than nine fields per
line, and that the first line has the ordering of those fields,
starting at one, and monotonically increasing by one. In other words,
you can't skip any numbers.

The map { $digits{$_} - 1 } is where the strings are being transformed
to (one less than) their equivalent numbers.

# perldoc -f map

You'll also note that I never declare a variable before I actually
have to. That will ensure that the scope of the variable is as limited
as necessary.

> Can someone please tell me where I have gone wrong and what I might do
> to solve the problem. I am still coming to terms with many of the
> concepts of perl and pointers to the relevant page(s) in the Llama or
> Camel books would also be welcome.

I hope I've pointed out what you did wrong (undef instead of defined),
and also have given you some pointers on how to write more perl-like
programs, using one of the strengths of Perl (hash and array slices).

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Tue, 10 Oct 2000 02:15:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: List as keys for hash
Message-Id: <39E27CBA.5FEE1428@rochester.rr.com>

Ian Petts wrote:
> 
> I have a semi-colon seperated list that I need to re-arrange the field
> order on. The order of the fields differs from file to file, and I need
> to change them to a pre-determined order. The order of the file can be
> determined from the first line. Take the following file for example:
> 
>         one;two;five;four;three
>         1;10Oct2000;bbbbb;aaaaa;12:00:00
>         2;10Oct2000;sxsxd;cassc;12:01:00
>         3;10Oct2000;sfgsf;aaeee;12:02:30
> 
> I need to re-arrange all fields in the order one, two, three, four,
> five.
> 
> With my rather limited Perl experience, I have come up with the
> following:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use diagnostics;
> 
> my $i;
> my $x;
> my $line;
> my @record;
> my %entry;
> my @goodnames = qw(one two three four five);
> 
> $line = <STDIN>;
> chomp($line);
> 
> for ($i=0; $i <= $#goodnames; $i++) {
>   print "$goodnames[$i]";
>   print ";" unless ($i == $#goodnames);
> }
> print "\n";
> 
> my @badnames = split(/;/, $line);
> 
> while ($line = <STDIN>) {
>   chomp($line);
>   @record = split(/;/, $line);
>   $x = 0;
>   foreach $i (@badnames) {
>     $entry{$i} = $record[$x];
>     $x++;
>   }
>    for ($i=0; $i <= $#goodnames; $i++) {
>      print $entry{$goodnames[$i]} unless undef($entry{$goodnames[$i]});
>      print ";" unless ($i == $#goodnames);
>    }
>   print "\n";
> }
> 
> Running the program produces the following:
> 
> # cat filename | ./program.pl
> 
> one;two;three;four;five
> Use of uninitialized value in print at ./program.pl line 33, <STDIN>
> line 2 (#1)
> 
>     (W uninitialized) An undefined value was used as if it were already
> defined.  It was
>     interpreted as a "" or a 0, but maybe it was a mistake.  To suppress
> this
>     warning assign a defined value to your variables.
> 
> ;;;;
> Use of uninitialized value in print at ./program.pl line 33, <STDIN>
> line 3 (#1)
> ;;;;
> Use of uninitialized value in print at ./program.pl line 33, <STDIN>
> line 4 (#1)
> ;;;;
> 
> Can someone please tell me where I have gone wrong and what I might do
> to solve the problem. I am still coming to terms with many of the
> concepts of perl and pointers to the relevant page(s) in the Llama or
> Camel books would also be welcome.
 ...
> Ian.
 ...
Well, you've got some plenty hacked-up stuff in there.  The main problem
in line 33 is that you are using the undef function where you should
probably be using the defined function.  The undef function *undefines*
the hash entry you apparently think you are testing.  Then, when undef
succeeds in undefining the hash element (by returning undef!), you go
ahead and reference the hash element in the print statement, and get
your error message.  Replacing undef with defined, however, shows that
you have the wrong sense on the unless for defined.  Replacing unless
with if gets rid of the error message and it then prints stuff that is
almost correct.  It is missing column 1.  That is because your data (as
contained in your note) has leading spaces.  Deleting those leading
spaces from the data file generates the desired response.

The whole thing could be, I'm sure, reduced to a few lines (hint:  hash
slices), but I'll leave that as an exercise for you.
-- 
Bob Walton


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

Date: 09 Oct 2000 18:03:22 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: need blanks at end of format line
Message-Id: <m3aecdaa85.fsf@dhcp11-177.support.tivoli.com>

Mark Rogaski <wendigo@deathstar.jabberwock.org> writes:

> An entity claiming to be onkeerbaar@hotmail.com wrote:
> 
> : so far I have been unable to get the spaces on the end via format.
> 
> : The other lines are nice enough to have text in pos 94, and those work
> : fine.
> 
> : any ideas!?
> 
> 
> format FOO =
> @<<<<<<<<<<<<<<<< @|||||||||||||||||||| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> $bar,             $baz,                 " "
> .
> 
> where the last field is the padding field.  This is copacetic under -w, too.

Did you try it?

First, unless I'm missing something, I would expect that you would
want that last field to be right-justified (@>>>>).  Second, it
doesn't seem to work in either case.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 10 Oct 2000 03:16:54 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: need blanks at end of format line
Message-Id: <39E28CEE.F05EA21E@home.com>


Ren Maddox wrote:
> 
> First, unless I'm missing something, I would expect that you would
> want that last field to be right-justified (@>>>>).  Second, it
> doesn't seem to work in either case.

That's right, you can't create trailing spaces with formats.  Either use
printf or put some junk on the end

    @<<<< trailing_junk

and run it through a filter that strips off "trailing_junk".

-- 
Rick Delaney
rick.delaney@home.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 4566
**************************************


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