[21927] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4149 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 20 14:07:43 2002

Date: Wed, 20 Nov 2002 11:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 20 Nov 2002     Volume: 10 Number: 4149

Today's topics:
        Access a Hash with $a{...} AND $a{...}[0] the same way. (Christoph Bergmann)
    Re: Can someone recommend a beginner's book on Perl? <bart.lateur@pandora.be>
    Re: Can someone recommend a beginner's book on Perl? <p.lord@russet.org.uk>
    Re: Fields in /etc/passwd (Walter Roberson)
        if statment help <44movies@warpdriveonline.com>
    Re: if statment help <jurgenex@hotmail.com>
    Re: if statment help <fxn@hashref.com>
    Re: if statment help <ian@WINDOZEdigiserv.net>
    Re: if statment help (Tad McClellan)
    Re: if statment help (Tad McClellan)
    Re: if statment help (Tad McClellan)
    Re: if statment help <ian@WINDOZEdigiserv.net>
    Re: mod_perl @INC path question (Bryan Castillo)
    Re: nslookup and perl <jwillmore@cyberia.com>
        Perl CGI - Apache SSI - Need Advice <LaoTzu@TaoTeChing.co.uk.us>
        perl format <jvallanc@hgmp.mrc.ac.uk>
    Re: perl format <stevenm@blackwater-pacific.com>
    Re: perl format <Graham.T.Wood@oracle.com>
        Question about interpolation during substitution <a@b.com>
    Re: Sorting an array (Tad McClellan)
    Re: Sorting an array <barryk2@delete_me.mts.net>
    Re: Sorting an array <michi@relay3.jackal-net.at>
    Re: Sorting an array (Tad McClellan)
    Re: variable & class (Tad McClellan)
    Re: variable & class <el.chocho@laposte.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Nov 2002 07:06:16 -0800
From: baseportal2@hotmail.com (Christoph Bergmann)
Subject: Access a Hash with $a{...} AND $a{...}[0] the same way... / use of tie
Message-Id: <318b15ac.0211200706.9fa6708@posting.google.com>

Given a subroutine which returns a hash of arrays, something like:

$result{Name}[0]
$result{Street}[0]
$result{Name}[1]
 ...etc.

Sometimes it returns only one result, thus there would be

$result{Name}[0]
$result{Street}[0]

only. For convenience I would like to access the resulting hash with

$result{Name}
$result{Street}

in this case, but I don't want to differ with

ref $result{Name} eq "HASH"?$result{Name}[0]:$result{Name}

all the time (wouldn't be very convenient at all).

This means, what I want is:

$result{Name}
$result{Street}

should return the first "row" of the results, whether there is only
one result or more, and

$result{Name}[$i]
$result{Street}[$i]

should return the row $i of the results, whether there is one result
or more... (with only one result only $result{...}[0] makes sense, of
course)


This is the problem and I tried to solve it with "tie":

tie %result, 'test';

$result{Name}[0]="Mark";

print $result{Name}."\n";

print $result{Name}[0]."\n";


package test;

sub TIEHASH { bless {} }

sub FETCH 
{
	my($self, $key)=@_;  

	print "FETCH - wantarray=".wantarray." - (ref self=$self,
key=$key)=".ref($self->{$key})."\n";

	if(defined($self->{$key}[0]))	# called with $result{...} ???
	{
		return $self->{$key}[0];
	} else
	{
		return $self->{$key};
	}
}

sub STORE
{
	my($self, $key, $value)=@_;  
	$self->{$key}=$value;
}


but this doesn't work, because whether FETCH is called from
$result{Name} or from $result{Name}[0] - it doesn't "know" the
difference...

Anybody any ideas?

Best regards,

Christoph Bergmann


--
http://baseportal.com - free and easy web-based database


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

Date: Wed, 20 Nov 2002 14:26:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Can someone recommend a beginner's book on Perl?
Message-Id: <ee6ntugq9qu4fi2dsitrl1039c6b7qdr9f@4ax.com>

Phillip Lord wrote:

>  Tassilo> Turn that around: If you must sit in front of a computer
>  Tassilo> solving a problem, would you rather like to do it in a more
>  Tassilo> natural way or a rather less natural (clinically looking)
>  Tassilo> way? Perl's syntax can be quite suggestive. That is a big
>  Tassilo> strength.
>
>I'm a scientist. Most of the problems that I want the computer to
>solve are not expressible in natural language. When sitting at a
>computer, the semantics of what I am doing are the complex thing. I
>want a simple, straightforward, and unambiguous syntax, which does not
>get in the way. 

You're missing the point. The simple, straightforward syntax is the
thing that gets in the way.

Imagine how one would have to write

	$string = join ', ', @array;

on a simple, straightforward language that has no idea on how to do
join(). Then you'd have to write something like:

	$string = "";
	foreach my $item (@array) {
	    if($string ne "") {
	        $string .= ", ";
	    }
	    $string .= $item;
	}

As you can see, it's something a beginner can understand, but it is
verbose to write and extremely easy to get wrong.

As a scientist, you should appreciate the advantage of  not having to
speak about your advanced scientific stuff in kindergarten-terms all the
time. The science-field specific lingo is much easier to use, but you do
have to learn the language first.

-- 
	Bart.


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

Date: 20 Nov 2002 15:28:34 +0000
From: Phillip Lord <p.lord@russet.org.uk>
Subject: Re: Can someone recommend a beginner's book on Perl?
Message-Id: <vfadk4jm59.fsf@rpc71.cs.man.ac.uk>

>>>>> "Bart" == Bart Lateur <bart.lateur@pandora.be> writes:

  Bart> Phillip Lord wrote:

  Tassilo> Turn that around: If you must sit in front of a computer
  Tassilo> solving a problem, would you rather like to do it in a more
  Tassilo> natural way or a rather less natural (clinically looking)
  Tassilo> way? Perl's syntax can be quite suggestive. That is a big
  Tassilo> strength.
  >>
  >> I'm a scientist. Most of the problems that I want the computer to
  >> solve are not expressible in natural language. When sitting at a
  >> computer, the semantics of what I am doing are the complex
  >> thing. I want a simple, straightforward, and unambiguous syntax,
  >> which does not get in the way.

  Bart> You're missing the point. The simple, straightforward syntax
  Bart> is the thing that gets in the way.

  Bart> Imagine how one would have to write

  Bart> 	$string = join ', ', @array;

  Bart> on a simple, straightforward language that has no idea on how
  Bart> to do join(). Then you'd have to write something like:

  Bart> 	$string = ""; foreach my $item (@array) {
  Bart> 	    if($string ne "") {
  Bart> 	        $string .= ", ";
  Bart> 	    } $string .= $item;
  Bart> 	}

You are, I think, confusing the language syntax of perl, and the
functions it offers. If the language that I was working in did not
have a join operator, as perl does, then I would write a function to
do it, as you describe, and then call that instead. 

The complexity of perl's syntax is well known. "Nothing but perl can
parse Perl". Good eh? Sadly my editor can't parse perl correctly
either, so the syntax highlighting fails, which is a pity because I
like syntax highlighting. 

Sometimes it confuses perl as well...


"For example, if you wanted a function to make a new hash and return a
reference to it, you have these options:

    sub hashem {        { @_ } }   # silently wrong
    sub hashem {       +{ @_ } }   # ok
    sub hashem { return { @_ } }   # ok

On the other hand, if you want the other meaning, you can do this:

    sub showem {        { @_ } }   # ambiguous (currently ok, but may change)
    sub showem {       {; @_ } }   # ok
    sub showem { { return @_ } }   # ok

Note how the leading +{ and {; always serve to disambiguate the
expression to mean either the HASH reference, or the BLOCK."





  Bart> As you can see, it's something a beginner can understand, but
  Bart> it is verbose to write and extremely easy to get wrong.

  Bart> As a scientist, you should appreciate the advantage of not
  Bart> having to speak about your advanced scientific stuff in
  Bart> kindergarten-terms all the time. The science-field specific
  Bart> lingo is much easier to use, but you do have to learn the
  Bart> language first.

That depends. Jargon has it's place, but also it's disadvantages. It
can be used to express clearly, or, as is often the case, to
confuse. I am claiming that, for me, perl's syntax (and secondly that
ability to do things in some many ways) confuses me more than it helps
me. This is my opinion, and my point of view. You are welcome to have
your own, of course. But this is the result of my experience of using
perl a reasonable amount. 

Phil


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

Date: 20 Nov 2002 18:33:27 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Fields in /etc/passwd
Message-Id: <argkhn$j1t$1@canopus.cc.umanitoba.ca>
Keywords: Remove WINDOZE to reply

In article <m4vmtuobt308mc95fod0un6r33qcm1q5ke@4ax.com>,
Ian.H  <ian@WINDOZEdigiserv.net> wrote:
:I think you could use something like:

:if ($username !~ /[a-z][A-Z][0-9]_/) {
:  die "Illegal chars in username\n";
:}

That pattern matches if *anywhere* in the username there is a four
character sequence consisting of a lower-case alphabetic
character followed by an uppercase alphabetic character followed by
a numeric digit followed by an underscore. This would, I imagine,
match very few usernames. Perhaps you meant  /^[a-zA-Z0-9_]+$/ ?

The traditional definition of usernames does not allow underscores,
by the way. Older tradition disallows uppercase in usernames
(but many implimentations allow that now). Usernames also should not
begin with a digit.


:if ($uid !~ /[0-9]/) {
:  die "Illegal chars in UserID\n";
:}

That matches if there is a digit anywhere in the uid.


:if ($giu !~ /[0-9]/) {
:  die "Illegal chars in GroupID\n";
:}

Ditto with respect to the guid.

For these last two, you should use  /^[0-9]+$/  or better yet  /^\d+$/
--
   "No one has the right to destroy another person's belief by
   demanding empirical evidence."            -- Ann Landers


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

Date: Wed, 20 Nov 2002 11:11:17 -0500
From: "Mike" <44movies@warpdriveonline.com>
Subject: if statment help
Message-Id: <A9CdnfHPKMXnKEagXTWc3w@warpdrive.net>

The simple things are driving me crazy today.  Ok, I have a subroutine that
checks a name for invalid chars and badwords so someone can't register the
name "cock" or "../badstuff".

The program opens a file handle BADWORDS which is a one per line file of
words we don't want registered

ok...The if statment in the while loop is the problem.  If I use 'eq'
nothing ever matches, if I use '==' everything matches... any idea what I'm
doing wrong here?


Here it is:

sub checkUsername() {
    if ($username =~ /^[a-zA-Z0-9-)+$/) {
        print STDOUT "good\n";
    } else {
        exit;
    }
    while(<BADWORDS>) {
        if ($username eq $_) {
            print STDOUT "BADWORD!\n";
            exit;
        } else {
            print STDOUT "good";
        }
    }
    print STDOUT "Name check complete\n";
}




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

Date: Wed, 20 Nov 2002 16:25:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: if statment help
Message-Id: <AHOC9.16854$Q27.8947@nwrddc01.gnilink.net>

Mike wrote:
> The simple things are driving me crazy today.  Ok, I have a
> subroutine that checks a name for invalid chars and badwords so
> someone can't register the name "cock" or "../badstuff".
>
> The program opens a file handle BADWORDS which is a one per line file
> of words we don't want registered
>
> ok...The if statment in the while loop is the problem.  If I use 'eq'
> nothing ever matches, if I use '==' everything matches... any idea
> what I'm doing wrong here?

The operator == compares the numerical value, typically both variables (the
entered name and the badword) will have a numerical value of 0.

> Here it is:
>
> sub checkUsername() {
>     if ($username =~ /^[a-zA-Z0-9-)+$/) {
>         print STDOUT "good\n";
>     } else {
>         exit;
>     }

I don't see where you open the filehandle BADWORDS.
If you open it once outside of this sub then at least you may want to reset
the filepointer for each new username.

>     while(<BADWORDS>) {
>         if ($username eq $_) {
Your line from BADWORDS contains a closing newline, your $username most
likely does not. Therefore they will never be equal.
Please see "perldoc -f chomp".
[...]

jue




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

Date: 20 Nov 2002 17:29:43 +0100
From: Xavier Noria <fxn@hashref.com>
Subject: Re: if statment help
Message-Id: <878yzo8ars.fsf@kodo.localdomain>

"Mike" <44movies@warpdriveonline.com> writes:

: The simple things are driving me crazy today.  Ok, I have a subroutine that
: checks a name for invalid chars and badwords so someone can't register the
: name "cock" or "../badstuff".
: 
: The program opens a file handle BADWORDS which is a one per line file of
: words we don't want registered
: 
: ok...The if statment in the while loop is the problem.  If I use 'eq'
: nothing ever matches, if I use '==' everything matches... any idea what I'm
: doing wrong here?
: 
: 
: Here it is:
: 
: sub checkUsername() {
:     if ($username =~ /^[a-zA-Z0-9-)+$/) {
:         print STDOUT "good\n";
:     } else {
:         exit;
:     }
:     while(<BADWORDS>) {

$_ comes with an ending newline here, try adding

          chomp;

:         if ($username eq $_) {
:             print STDOUT "BADWORD!\n";
:             exit;

This "exit" ends the whole program, maybe you mean "return" there.

-- fxn


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

Date: Wed, 20 Nov 2002 16:39:40 +0000
From: Ian.H <ian@WINDOZEdigiserv.net>
Subject: Re: if statment help
Message-Id: <djentu4s6fhiak53p2ksp8ug2bevfkf7i9@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on 20 Nov 2002 17:29:43 +0100, Xavier Noria
<fxn@hashref.com> managed to scribble:

> "Mike" <44movies@warpdriveonline.com> writes:
> 
> : The simple things are driving me crazy today.  Ok, I have a
> subroutine that : checks a name for invalid chars and badwords so
> someone can't register the : name "cock" or "../badstuff".
> : 
> : The program opens a file handle BADWORDS which is a one per line
> file of : words we don't want registered
> : 
> : ok...The if statment in the while loop is the problem.  If I use
> 'eq' : nothing ever matches, if I use '==' everything matches... any
> idea what I'm : doing wrong here?
> : 
> : 
> : Here it is:
> : 
> : sub checkUsername() {
> :     if ($username =~ /^[a-zA-Z0-9-)+$/) {
                           ^^^^^^^^^^^^^
Doesn't this need to be fixed?

  if ($username =~ /^[a-z][A-Z][0-9]\-\)\+$/) {

[snip]


Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPdu6ymfqtj251CDhEQI5ngCfTKQ/jfMYPZJnyFK6sDnoAB2DELQAoLKb
7mxdDjoPF2vz+Uv9Xy2iMnuq
=zyiy
-----END PGP SIGNATURE-----

-- 
Ian.H  (Design & Development)
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Wed, 20 Nov 2002 10:31:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: if statment help
Message-Id: <slrnatne68.3pv.tadmc@magna.augustmail.com>

Mike <44movies@warpdriveonline.com> wrote:

>     if ($username =~ /^[a-zA-Z0-9-)+$/) {
                         ^          ^
                         ^          ^


Please do not re-type Perl code

   Use copy/paste or your editor's "import" function rather than
   attempting to type in your code. If you make a typo you will get
   followups about your typos instead of about the question you are
   trying to get answered.


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


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

Date: Wed, 20 Nov 2002 10:46:17 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: if statment help
Message-Id: <slrnatnf2p.3pv.tadmc@magna.augustmail.com>

Mike <44movies@warpdriveonline.com> wrote:

> The simple things are driving me crazy today.  


Something as simple as adding:

   print "'$_' is a bad word\n";

in your while() loop would have revealed the problem.


> If I use 'eq'
> nothing ever matches, 


Print out the 2 things being compared, and you can find out why
they are not equal.


> if I use '==' everything matches... 


You should always enable warnings when developing Perl code.

It would have pointed out why they are all matching.


> any idea what I'm
> doing wrong here?


Not enabling warnings.

Using global variables instead of subroutine arguments.

Missing a chomp().


> sub checkUsername() {
>     if ($username =~ /^[a-zA-Z0-9-)+$/) {
          ^^^^^^^^^


Global variables should be avoided whenever possible.

Pass the username as a subroutine argument instead.


>     while(<BADWORDS>) {


   chomp;


>         if ($username eq $_) {


$_ has a newline at the end.

Does $username also have a newline at the end?


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


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

Date: Wed, 20 Nov 2002 10:53:32 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: if statment help
Message-Id: <slrnatnfgc.3rs.tadmc@magna.augustmail.com>

Ian.H <ian@WINDOZEdigiserv.net> wrote:
> In a fit of excitement on 20 Nov 2002 17:29:43 +0100, Xavier Noria
><fxn@hashref.com> managed to scribble:
>> "Mike" <44movies@warpdriveonline.com> writes:
>> 

>> :     if ($username =~ /^[a-zA-Z0-9-)+$/) {
>                            ^^^^^^^^^^^^^
> Doesn't this need to be fixed?


Of course.

The program is useless if it will not even compile.  :-)


>   if ($username =~ /^[a-z][A-Z][0-9]\-\)\+$/) {


But that does not fix it!

That matches only when $username is 6 (or 7) characters long.

It requires that the last 3 characters of the username be "-)+",
which seems a strange thing to allow.


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


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

Date: Wed, 20 Nov 2002 17:28:53 +0000
From: Ian.H <ian@WINDOZEdigiserv.net>
Subject: Re: if statment help
Message-Id: <dchntu4akbjncbg94339t2459rkh1eoepk@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Wed, 20 Nov 2002 10:53:32 -0600,
tadmc@augustmail.com (Tad McClellan) managed to scribble:

> Ian.H <ian@WINDOZEdigiserv.net> wrote:
> > In a fit of excitement on 20 Nov 2002 17:29:43 +0100, Xavier Noria
> ><fxn@hashref.com> managed to scribble:
> >> "Mike" <44movies@warpdriveonline.com> writes:
> >> 
> 
> >> :     if ($username =~ /^[a-zA-Z0-9-)+$/) {
> >                            ^^^^^^^^^^^^^
> > Doesn't this need to be fixed?
> 
> 
> Of course.
> 
> The program is useless if it will not even compile.  :-)
> 
> 
> >   if ($username =~ /^[a-z][A-Z][0-9]\-\)\+$/) {
> 
> 
> But that does not fix it!
> 
> That matches only when $username is 6 (or 7) characters long.
> 
> It requires that the last 3 characters of the username be "-)+",
> which seems a strange thing to allow.

Tad,

- From reading your followup posts, I firstly, misread the concept being
used (by missing the point that the ')' should probably have really
been a ']').

The rest, I can only say I've learnt something myself. I agree also,
that requiring '-)+' for the last 3 chars would seem very strange.


Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPdvGU2fqtj251CDhEQJJJQCgrleL/ridQE1RKT7hsTq6Kq880PIAoN5E
u+Cx+g8qT3mgKrjdj1Cw83Yg
=BjIe
-----END PGP SIGNATURE-----

-- 
Ian.H  (Design & Development)
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: 20 Nov 2002 07:17:24 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: mod_perl @INC path question
Message-Id: <1bff1830.0211200717.3444a207@posting.google.com>

"Tulan W. Hu" <twhu@lucent.com> wrote in message news:<ardec1$hbj@netnews.proxy.lucent.com>...
> You or someone use Perl 5.8.0 to build the mod_perl,
> you need to use Perl 5.8.0 in your script to access the handle.
> 
> "dave" <dave@dave.com> wrote in message
> > Does anyone know why my mod_perl INC path would be different to the
> > standard perl one? or how i can change it so it is the same as the
> > standard perl one

You can set the environment variable PERL5LIB from your apache config
file using the SetEnv directive.  I don't know if this will solve your
problem, but it will allow you to modify @INC, to see if you really
have some other issue.

See the Environment section of perlrun
http://www.perldoc.com/perl5.6.1/pod/perlrun.html#ENVIRONMENT

Docs for Apache directive SetEnv
http://httpd.apache.org/docs/mod/mod_env.html#setenv


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

Date: Wed, 20 Nov 2002 16:55:22 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: nslookup and perl
Message-Id: <20021120003614.543f98af.jwillmore@cyberia.com>

> Hey guys,

You know, in our PC society today, gals code to ;)

> I have a question about nslookup and perl.
> I try to make a script which lists all cnames off a node and write
> it to a file, but I can't handle the nslookup commands.
> 
> in the shell it's easy just type nslookup wait and then
> ls -t CNAME domain, but you can't figure out this command to put
> that on one line or how to code it in perl,
> can someone help me please I'm really confiused.

I believe someone has already gone through a lot of pain and developed
a module or two that may fit the bill.  A search of
http://search.cpan.org/ may prove helpful.

If you want to do it by yourself, consult your local Perl
documentation on IPC (Inter Process Communications).  That prove
helpful.

HTH

Jim


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

Date: Wed, 20 Nov 2002 12:50:53 -0500
From: "Lao Tzu" <LaoTzu@TaoTeChing.co.uk.us>
Subject: Perl CGI - Apache SSI - Need Advice
Message-Id: <XKPC9.40157$dr6.9632@news.bellsouth.net>

Hi all, I have a question about how to pass form data with CGI and SSI.

I have an HTML page with a perl cgi script included.  The CGI creates a form
and takes its input and then prints output based on the input.  I have the
form action set to the cgi ( action="/cgi-bin/test.cgi" ), the problem is
that when the form is submitted, the only thing that gets printed to the
screen is the cgi output.  How can I include the cgi output as part of the
SSI page ?

Any and all assistance is greatly appreciated.

Thanks.





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

Date: Wed, 20 Nov 2002 14:13:49 +0000
From: "Miss J.L. Vallance" <jvallanc@hgmp.mrc.ac.uk>
Subject: perl format
Message-Id: <3DDB989D.127BB381@hgmp.mrc.ac.uk>

I am using Perl formats, which is a tool perl provides for creating
reports and charts.

An example basic syntax is:

format STDOUT =
@|||||||||||||||||||||||||||||||||
$text
 .
$text = 'My name is Jayne'
write;

However, I have problems with using this when I try to put more than one
of the above
format statements in one perl script. It will only ever take notice of
the last format STDOUT
statement.

Is that just the way it is, or can I have more than 1 seperate  'format
STDOUT  -> write;' statements in one script?
Maybe I can't, but if I want to format the output from a loop, and I
wanted
to format a header piece of text, in the same script, how could
I acheive this.

Many thanks

Jayne



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

Date: Wed, 20 Nov 2002 06:58:34 -0800
From: Steven May <stevenm@blackwater-pacific.com>
Subject: Re: perl format
Message-Id: <arg7lv$8jq$1@quark.scn.rain.com>

Miss J.L. Vallance wrote:
> I am using Perl formats, which is a tool perl provides for creating
> reports and charts.
> 
> An example basic syntax is:
> 
> format STDOUT =
> @|||||||||||||||||||||||||||||||||
> $text
> .
> $text = 'My name is Jayne'
> write;
> 
> However, I have problems with using this when I try to put more than one
> of the above
> format statements in one perl script. It will only ever take notice of
> the last format STDOUT
> statement.
> 
> Is that just the way it is, or can I have more than 1 seperate  'format
> STDOUT  -> write;' statements in one script?
> Maybe I can't, but if I want to format the output from a loop, and I
> wanted
> to format a header piece of text, in the same script, how could
> I acheive this.
> 
> Many thanks
> 
> Jayne
> 


Hmmm..... stop a minute and think.

The standard syntax for formats is

format NAME =
FORMLIST
 .

where NAME is configurable.

So if you created a format named HEADER and another named LOOP and.....

hth,

s.



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

Date: Wed, 20 Nov 2002 14:59:22 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: perl format
Message-Id: <3DDBA34A.72B56D5@oracle.com>

"Miss J.L. Vallance" wrote:

> using Perl formats <snip> if I want to format the output from a loop, and
> I
> wanted to format a header piece of text, in the same script, how could
> I achieve this.

You can define a header format with the name STDOUT_TOP then fake a new page
by setting $- (lines left on current page) to 0.

You could also have multiple different formats and select which one to use
by assigning its name to $~ (current format). The same thing works with
header records using $^ (current header format).

Read perldoc -f write for details.

Graham



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

Date: Wed, 20 Nov 2002 11:49:11 -0600
From: "MG" <a@b.com>
Subject: Question about interpolation during substitution
Message-Id: <3ddbc807_6@corp-goliath.newsgroups.com>

I have the following code:

my $search_text='(abc)d';
my $replacement_text='$1 some other text';
my $text='abcdef';

$text=~s/$search_text/$replacement_text/;

# Now I would like for $text to become: 'abc some other textdef'

--

In other words I want the $1 in the replacement text to be interpolated
after the match occurs and to be replaced with the captured characters from
the search text.


Thanks,

Mike






-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


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

Date: Wed, 20 Nov 2002 08:04:13 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sorting an array
Message-Id: <slrnatn5it.3b4.tadmc@magna.augustmail.com>

Blnukem <blnukem@hotmail.com> wrote:


> Flat File:
> 
> bill|4|1998
> ray|3|1954
> john|5|1967
> 
> How would I sort the array one the year?


The way the Perl FAQ says to:

   perldoc -q sort

If you don't understand the FAQ answer, then ask a question 
about the FAQ answer.


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


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

Date: Wed, 20 Nov 2002 08:20:12 -0600
From: godzilla <barryk2@delete_me.mts.net>
Subject: Re: Sorting an array
Message-Id: <MPG.18455614fd0c937e989758@east.usenetserver.com>

In article <0aMC9.30904$s02.3845@news4.srv.hcvlny.cv.net>, 
blnukem@hotmail.com says...
> Hi All
> 
> I'm reading flat file that looks like this into an array.
> 
> "$name $number $year"
> 
> Flat File:
> 
> bill|4|1998
> ray|3|1954
> john|5|1967
> 
> How would I sort the array one the year?
> 
> Thanx in advance Blnukem
> 
> 
> 

# Assuming @years , @names and @numbers hold the values from the file

@indexes = (0..$#years);
@indexes = sort { $list[$a] <=> $year[$b] } @indexes;
$count = scalar @years;
# Print the sorted info
for ( $loop = 0 ; $loop < $count ; ++$loop ) {
    $index = $indexes[$loop];
    printf "%s %d %d\n",$names[$index],$numbers[$index],$years[$index];
}
-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com



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

Date: Wed, 20 Nov 2002 14:26:54 +0000 (UTC)
From: Michael Lang <michi@relay3.jackal-net.at>
Subject: Re: Sorting an array
Message-Id: <slrnatn6th.jni.michi@nuddelaug.jackal-net.at>

In article <0aMC9.30904$s02.3845@news4.srv.hcvlny.cv.net>, Blnukem wrote:
> Hi All
> 
> I'm reading flat file that looks like this into an array.
> 
> "$name $number $year"
> 
> Flat File:
> 
> bill|4|1998
> ray|3|1954
> john|5|1967
> 

open (FILE,"$file) || die 
while (<FILE>)
 {	chomp;
	next unless ($_ =~ /^(.*)\|(\d+)\|(\d{4})$/);
	my ($year,$name,$value) = ($3,$1,$2);
	$records->{"$year"}->{"$name"} = $value;
	push @sort = $year;
 }
close(FILE);
@sort = sort ($a <=> $b) @sort;

foreach (@sort)
 {	print "$_ ";
	my $name = $records->{"$_"};
	my %name = $%name;
	foreach (keys (%name))
	 {	print "$_ $name->{$_}\n";	}
 }


how i could help ... 8)

Greetz mIke
> How would I sort the array one the year?
> 
> Thanx in advance Blnukem
> 
> 


-- 
Michael Lang				       System Engineer
EUnet-AG EDV und Internetdienstleistungen  Tel: +43 1 89933118
Diefenbachgasse 35, 1150 Wien		   Fax: +4318991110118
http://www.eunet-ag.at		      Michael.Lang@eunet-ag.at


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

Date: Wed, 20 Nov 2002 09:11:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sorting an array
Message-Id: <slrnatn9gg.3ir.tadmc@magna.augustmail.com>

Michael Lang <michi@relay3.jackal-net.at> wrote:

> open (FILE,"$file) || die 


Missing a (useless) double quote.

Missing semicolon.

Missing $! in die's argument.


> 	push @sort = $year;


Missing something. Maybe a fat comma ( => ) ?


> @sort = sort ($a <=> $b) @sort;


Used (parens) instead of {curlies}.


> 	my $name = $records->{"$_"};
                              ^  ^
                              ^  ^

Useless use of quotes.


> 	my %name = $%name;


Huh?

What on Earth do you expect that code to do?


> how i could help ... 8)


1) by not posting when you do not know the answer

2) by posting Perl code here in the Perl newsgroup


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


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

Date: Wed, 20 Nov 2002 08:00:14 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: variable & class
Message-Id: <slrnatn5be.3b4.tadmc@magna.augustmail.com>


[ Please don't top-post.

  Text rearranged to follow the usual convention.
]


Tulan W. Hu <twhu@lucent.com> top-posted:
> "Christophe" <christophe@all4website.com> wrote ...


>> package main;
>> classe::test();
>>
>> package classe;
>> my $var = 'contenu de var dans classe::';
>> sub test {
>>   print "VAR=$var";
>> }
> 
> 
> I ran classe.pl and it works fine.


Because you have rearranged things so that "my $var=" executes
before classe::test() executes.


> in classe.pl file:
> #! /usr/bin/perl
> use strict;
> use classe;


$var gets assigned at compile time (because "use" is compile time).


> package main;
> classe::test();


So it will be defined by the time execution gets to this point.


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


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

Date: Wed, 20 Nov 2002 15:19:24 +0100
From: Chocho <el.chocho@laposte.net>
Subject: Re: variable & class
Message-Id: <arg5sf$91v$1@news-reader12.wanadoo.fr>

OK, understood !
Thanks a lot for your help
Christophe

-- 

el.chocho@laposte.net




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

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


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