[14011] in Perl-Users-Digest
Perl-Users Digest, Issue: 1421 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 18 18:26:17 1999
Date: Thu, 18 Nov 1999 15:25:59 -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: <942967559-v9-i1421@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 18 Nov 1999 Volume: 9 Number: 1421
Today's topics:
Is there no length() function? (Bård Skaflestad)
Re: Is there no length() function? <jxu@wcom.net>
Re: Is there no length() function? <tbornhol@prioritytech.com>
Re: Is there no length() function? (Andrew Johnson)
Re: Is there no length() function? <newsposter@cthulhu.demon.nl>
Re: Is there no length() function? <tbornhol@prioritytech.com>
Re: Is there no length() function? (Bård Skaflestad)
Re: Is there no length() function? <r28629@email.sps.mot.com>
Re: Is there no length() function? <newsposter@cthulhu.demon.nl>
Re: Is there no length() function? (Brett W. McCoy)
Re: Is there no length() function? <rootbeer@redcat.com>
Re: Is there no length() function? (Brett W. McCoy)
Re: Is there no length() function? (Kragen Sitaker)
Re: Is there no length() function? (Kragen Sitaker)
Keeping string on same line <asd@ds.aw>
Re: Keeping string on same line <gellyfish@gellyfish.com>
Re: Keeping string on same line <asd@ds.aw>
Re: Keeping string on same line <gellyfish@gellyfish.com>
Re: Keeping string on same line <asd@ds.aw>
Re: Keeping string on same line (Martien Verbruggen)
Re: Keeping string on same line <koharikNOSPAM4ME@earthlink.net>
legal names and about sorting (Jaakko Puurunen)
Re: legal names and about sorting (Martien Verbruggen)
Re: legal names and about sorting (Jaakko Puurunen)
Re: legal names and about sorting <aqumsieh@matrox.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Nov 1999 21:22:00 +0100
From: bardsk@math.ntnu.no (Bård Skaflestad)
Subject: Is there no length() function?
Message-Id: <dfwk8nf7dp3.fsf@martens.math.ntnu.no>
Hi all Perl programmers.
The following may indeed be a wery simple case of misunderstanding. I
am however unable to figure it out. If any of you could shed some
light on this one I would be most grateful. As you will surely see
from my code, I am indeed a beginner at Perl but I have tried to read
the docs. But then again; it is entirely possible that I have
misinterpreted what the docs said as english is not my mother tounge.
Anyway, here is the code. Never mind the non-standard location of the
perl executable, it is in fact where it is located on my system.
<Code>
#!/store/bin/perl -w
#
# Reads a file on STDIN and determines the number of characters
# in its longest line.
use strict;
use diagnostics;
use vars qw($max $nchar);
$max = 0;
while (defined(<>)) {
$nchar = length($_);
$max = $nchar if ($nchar > $max);
}
print "Longest line is $length characters long\n";
</Code>
and that's it. Its intent should be fairly obvious, but something is
clearly wrong because the compilation phase produces the following:
<Errors>
Global symbol "length" requires explicit package name at
./maxlength.pl line 18 (#1)
(F) You've said "use strict vars", which indicates that all
variables must either be lexically scoped (using "my"), or
explicitly qualified to say which package the global variable is
in (using "::").
Execution of ./maxlength.pl aborted due to compilation errors (#2)
(F) The final summary message when a Perl compilation fails.
Uncaught exception from user code:
Execution of ./maxlength.pl aborted due to compilation errors.
</Errors>
Now, I do not think there is anything wrong with my perl executable so
the error *has* to be mine, but as I've stated before: I am unable to
figure it out. Has it got something to do with the way I read from
STDIN? Any and all comments are most welcome. Thanks in advance.
BTW, sorry about the long post.
--
Bård Skaflestad, student of mathematics at
The Norwegian University of Science and Technology
bardsk@stud.math.ntnu.no
------------------------------
Date: Thu, 18 Nov 1999 15:25:28 -0500
From: "Jun Xu" <jxu@wcom.net>
Subject: Re: Is there no length() function?
Message-Id: <811nff$j5s$1@news.cis.ohio-state.edu>
Bård Skaflestad <bardsk@math.ntnu.no> wrote in message
news:dfwk8nf7dp3.fsf@martens.math.ntnu.no...
> Hi all Perl programmers.
>
> The following may indeed be a wery simple case of misunderstanding. I
> am however unable to figure it out. If any of you could shed some
> light on this one I would be most grateful. As you will surely see
> from my code, I am indeed a beginner at Perl but I have tried to read
> the docs. But then again; it is entirely possible that I have
> misinterpreted what the docs said as english is not my mother tounge.
>
> use strict;
> use diagnostics;
>
> use vars qw($max $nchar);
>
> $max = 0;
>
> while (defined(<>)) {
> $nchar = length($_);
> $max = $nchar if ($nchar > $max);
> }
>
> print "Longest line is $length characters long\n";
> </Code>
>
> and that's it. Its intent should be fairly obvious, but something is
> clearly wrong because the compilation phase produces the following:
>
> <Errors>
> Global symbol "length" requires explicit package name at
> ./maxlength.pl line 18 (#1)
>
Function length() takes an array or hash as argument, not scalar.
------------------------------
Date: Thu, 18 Nov 1999 14:32:59 -0600
From: "Tim Bornholtz" <tbornhol@prioritytech.com>
Subject: Re: Is there no length() function?
Message-Id: <56FF9DC1CE375996.61AE5B423648AF68.205F761B8C17827B@lp.airnews.net>
> #!/store/bin/perl -w
> #
> # Reads a file on STDIN and determines the number of characters
> # in its longest line.
>
> use strict;
> use diagnostics;
>
> use vars qw($max $nchar);
>
> $max = 0;
>
> while (defined(<>)) {
> $nchar = length($_);
> $max = $nchar if ($nchar > $max);
> }
>
> print "Longest line is $length characters long\n";
how about:
print "Longest line is $max characters long\n";
hth,
Tim Bornholtz
tbornhol@prioritytech.com
------------------------------
Date: Thu, 18 Nov 1999 20:43:44 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Is there no length() function?
Message-Id: <4yZY3.3599$Zu4.43859@news1.rdc1.mb.home.com>
In article <811nff$j5s$1@news.cis.ohio-state.edu>,
Jun Xu <jxu@wcom.net> wrote:
[snip]
! Function length() takes an array or hash as argument, not scalar.
What language are you using?
perldoc -f length
=item length EXPR
=item length
Returns the length in characters of the value of EXPR. If EXPR is
omitted, returns length of C<$_>. Note that this cannot be used on
an entire array or hash to find out how many elements these have.
For that, use C<scalar @array> and C<scalar keys %hash> respectively.
andrew
------------------------------
Date: 18 Nov 1999 20:43:37 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Is there no length() function?
Message-Id: <811odp$2dr$1@internal-news.uu.net>
Jun Xu <jxu@wcom.net> wrote:
> Function length() takes an array or hash as argument, not scalar.
Where did you read that ???
Anyway, the variable $length is used where $max was meant to
be used. Also, why use while instead of foreach? Note that
the newlines at the end of the lines being read are counted
as well. You might want to remove them before determining
the length of the input line (see 'chomp' function)
<code>
use strict;
use diagnostics;
use vars qw($max $nchar);
$max = 0;
foreach (<>) {
$nchar = length($_);
$max = $nchar if ($nchar > $max);
}
print "Longest line is $max characters long\n";
</code>
Erik
------------------------------
Date: Thu, 18 Nov 1999 14:50:07 -0600
From: "Tim Bornholtz" <tbornhol@prioritytech.com>
Subject: Re: Is there no length() function?
Message-Id: <70859F4068C9E637.1EA07B5462B6FC0D.04FE7133778E74C8@lp.airnews.net>
Jun Xu <jxu@wcom.net> wrote in message
news:811nff$j5s$1@news.cis.ohio-state.edu...
> Bård Skaflestad <bardsk@math.ntnu.no> wrote in message
> news:dfwk8nf7dp3.fsf@martens.math.ntnu.no...
> > Hi all Perl programmers.
> > use strict;
> > use diagnostics;
> >
> > use vars qw($max $nchar);
> >
> > $max = 0;
> >
> > while (defined(<>)) {
> > $nchar = length($_);
> > $max = $nchar if ($nchar > $max);
> > }
> >
> > print "Longest line is $length characters long\n";
> > </Code>
> >
> > and that's it. Its intent should be fairly obvious, but something is
> > clearly wrong because the compilation phase produces the following:
> >
> > <Errors>
> > Global symbol "length" requires explicit package name at
> > ./maxlength.pl line 18 (#1)
> >
>
> Function length() takes an array or hash as argument, not scalar.
>
Where did you get that from? In reading perlfunc I see:
length EXPR
length Returns he length in characters of the value of EXPR. If EXPR is
omitted, returns length of $_.
Wrong information is worse than no information.
Tim Bornholtz
tbornhol@prioritytech.com
------------------------------
Date: 18 Nov 1999 21:59:40 +0100
From: bardsk@math.ntnu.no (Bård Skaflestad)
Subject: Re: Is there no length() function?
Message-Id: <dfwpux7ecsj.fsf@martens.math.ntnu.no>
"Tim Bornholtz" <tbornhol@prioritytech.com> writes:
> >
> > print "Longest line is $length characters long\n";
>
> how about:
> print "Longest line is $max characters long\n";
Indeed! Thank you for pointing that out to me. I guess I should go
home now and feel pretty stupid :) I must be more tired than I
thought. Ah, well nothing that a good nights sleep will not cure.
Again: Thank you all for helpful input. This NG is truly a treasure
trove of insight even though my "problem" didn't take much insight to
fix.
--
Bård Skaflestad, student of mathematics at
The Norwegian University of Science and Technology
bardsk@stud.math.ntnu.no
------------------------------
Date: Thu, 18 Nov 1999 14:59:19 -0600
From: TK Soh <r28629@email.sps.mot.com>
To: Jun Xu <jxu@wcom.net>
Subject: Re: Is there no length() function?
Message-Id: <383468A7.53156F51@email.sps.mot.com>
Jun Xu wrote:
> Function length() takes an array or hash as argument, not scalar.
huh !! :-0
------------------------------
Date: 18 Nov 1999 21:24:41 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Is there no length() function?
Message-Id: <811qqp$3m0$1@internal-news.uu.net>
Erik van Roode <newsposter@cthulhu.demon.nl> wrote:
> Also, why use while instead of foreach?
Ignore that remark. It doesn't make sense to me, even though
it did when I posted it.
Erik
------------------------------
Date: Thu, 18 Nov 1999 21:42:46 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Is there no length() function?
Message-Id: <slrn838sr1.e6g.bmccoy@moebius.foiservices.com>
Also Sprach Bård Skaflestad <bardsk@math.ntnu.no>:
>#!/store/bin/perl -w
>#
># Reads a file on STDIN and determines the number of characters
># in its longest line.
>
>use strict;
>use diagnostics;
Good. You have read the documentation and put in the proper diagnostic
options.
>use vars qw($max $nchar);
>
>$max = 0;
>
>while (defined(<>)) {
> $nchar = length($_);
> $max = $nchar if ($nchar > $max);
>}
>
>print "Longest line is $length characters long\n";
^^^^^^^
Aha! You don't have this defined! You want this to be $max, don't you?
--
Brett W. McCoy bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek) http://www.foiservices.com
FOI Services, Inc./DIOGENES 301-975-0110
---------------------------------------------------------------------------
------------------------------
Date: Thu, 18 Nov 1999 13:49:37 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Is there no length() function?
Message-Id: <Pine.GSO.4.10.9911181348170.16575-100000@user2.teleport.com>
On 18 Nov 1999, B=E5rd Skaflestad wrote:
[ Code snipped except for line 18 ]
> print "Longest line is $length characters long\n";
> Global symbol "length" requires explicit package name at
> ./maxlength.pl line 18 (#1)=20
You used 'use strict', but you never declared $length. Oops!
--=20
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 18 Nov 1999 21:44:57 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Is there no length() function?
Message-Id: <slrn838sv4.e6g.bmccoy@moebius.foiservices.com>
Also Sprach Jun Xu <jxu@wcom.net>:
>Function length() takes an array or hash as argument, not scalar.
No it doesn't. It takes an arbitrary expression, or $_ if there is no
argument, and returns the length in bytes.
--
Brett W. McCoy bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek) http://www.foiservices.com
FOI Services, Inc./DIOGENES 301-975-0110
---------------------------------------------------------------------------
------------------------------
Date: Thu, 18 Nov 1999 22:30:13 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Is there no length() function?
Message-Id: <V5%Y3.26121$YI2.1172280@typ11.nn.bcandid.com>
In article <811nff$j5s$1@news.cis.ohio-state.edu>, Jun Xu <jxu@wcom.net> wrote:
>Function length() takes an array or hash as argument, not scalar.
Wrong.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Thu, 18 Nov 1999 22:33:50 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Is there no length() function?
Message-Id: <i9%Y3.26123$YI2.1159950@typ11.nn.bcandid.com>
In article <dfwk8nf7dp3.fsf@martens.math.ntnu.no>,
Bård Skaflestad <bardsk@math.ntnu.no> wrote:
>while (defined(<>)) {
Lots of people have commented, but none of them seem to notice that
you're using while (defined(<>)) instead of while (<>). At a minimum,
this will keep <> from assigning to $_, and I'm not sure what context
<> is going to get from defined(), so it might end up reading the whole
file.
Oh, and you're not necessarily reading from STDIN with <>; <STDIN>
reads from STDIN, but <> might read from files whose names you pass on
the command line.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Thu, 18 Nov 1999 14:31:29 +0100
From: "Jakob" <asd@ds.aw>
Subject: Keeping string on same line
Message-Id: <810viq$qn0@sdaw04.seinf.abb.se>
Hi All.
I've got a small, but annoying problem.
I need to output a string, and then update the string but keep the string on
the
same line. Ie I need to update the status field contained within the string.
Please bear in mind that this is NOT a Tk script.
Anybody got a good suggestion ?
Rgdrs
Jakob
------------------------------
Date: 18 Nov 1999 13:49:24 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Keeping string on same line
Message-Id: <383403e4_1@newsread3.dircon.co.uk>
Jakob <asd@ds.aw> wrote:
> Hi All.
>
> I've got a small, but annoying problem.
>
> I need to output a string, and then update the string but keep the string on
> the
> same line. Ie I need to update the status field contained within the string.
> Please bear in mind that this is NOT a Tk script.
>
> Anybody got a good suggestion ?
>
E.G :
$| = 1;
for ( 1 ... 1000 )
{
print "\b\b\b\b";
printf "%.4d",$_;
sleep 1;
}
Alternatively you might look at Term::Cap, Term::Screen or Curses modules
from CPAN <http://www.cpan.org>
/J\
--
"He is marvelous at beating men and achieving real penetration" -
Alex Ferguson
------------------------------
Date: Thu, 18 Nov 1999 15:00:02 +0100
From: "Jakob" <asd@ds.aw>
Subject: Re: Keeping string on same line
Message-Id: <811188$p8a@sdaw04.seinf.abb.se>
Yeah, sort of but that does'nt really do it.
First of all, I tried that approach first, but it deosnt generate any output
at all !
Second : The length of the updated field might vary, so what I
would prefer is to re-write the whole string that contains the
update field.
Thanks anyway !!!
/ J
Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
news:383403e4_1@newsread3.dircon.co.uk...
> Jakob <asd@ds.aw> wrote:
> > Hi All.
> >
> > I've got a small, but annoying problem.
> >
> > I need to output a string, and then update the string but keep the
string on
> > the
> > same line. Ie I need to update the status field contained within the
string.
> > Please bear in mind that this is NOT a Tk script.
> >
> > Anybody got a good suggestion ?
> >
>
> E.G :
>
> $| = 1;
> for ( 1 ... 1000 )
> {
> print "\b\b\b\b";
> printf "%.4d",$_;
> sleep 1;
> }
>
> Alternatively you might look at Term::Cap, Term::Screen or Curses modules
> from CPAN <http://www.cpan.org>
>
> /J\
> --
> "He is marvelous at beating men and achieving real penetration" -
> Alex Ferguson
------------------------------
Date: 18 Nov 1999 14:31:56 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Keeping string on same line
Message-Id: <38340ddc_1@newsread3.dircon.co.uk>
Jakob <asd@ds.aw> wrote:
> Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
> news:383403e4_1@newsread3.dircon.co.uk...
>> Jakob <asd@ds.aw> wrote:
>> > Hi All.
>> >
>> > I've got a small, but annoying problem.
>> >
>> > I need to output a string, and then update the string but keep the string on
>> > the
>> > same line. Ie I need to update the status field contained within the
> string.
>> > Please bear in mind that this is NOT a Tk script.
>> >
>> > Anybody got a good suggestion ?
>> >
>>
>> E.G :
>>
>> $| = 1;
>> for ( 1 ... 1000 )
>> {
>> print "\b\b\b\b";
>> printf "%.4d",$_;
>> sleep 1;
>> }
>>
>> Alternatively you might look at Term::Cap, Term::Screen or Curses modules
>> from CPAN <http://www.cpan.org>
>>
> Yeah, sort of but that does'nt really do it.
>
> First of all, I tried that approach first, but it deosnt generate any output
> at all !
>
Er thats why it has $| = 1; in it - I bet you didnt try it .
> Second : The length of the updated field might vary, so what I
> would prefer is to re-write the whole string that contains the
> update field.
>
Then get the length of the string first and then use that many backspaces.
You obviously failed to read my suggestion to use Term::Cap or Term::Screen;
require Term::Screen;
$scr = new Term::Screen;
unless ($scr) { die " Something's wrong \n"; }
$scr->clrscr();
for ( 1...1000)
{
$scr->at(5,3)->bold()->puts(sprintf("%.4d",$_))->normal();
sleep 1;
}
/J\
--
"The teenage masturbators of today are the television executives of
tomorrow" - Melissa Cabriolet, Drop the Dead Donkey
------------------------------
Date: Thu, 18 Nov 1999 15:40:42 +0100
From: "Jakob" <asd@ds.aw>
Subject: Re: Keeping string on same line
Message-Id: <8113kj$s08@sdaw04.seinf.abb.se>
Geez, what's with the people on this forum. You're always clankin in newbies
asking
questions.
YES. I did try youre small bit of code, and it didnt do any difference.
Second, I have'nt installed the module yet. I will but I really would like
to
do this with the standard perl dist.
Anyway, thanks for your reply.
Rgrds
Jakob
Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
news:38340ddc_1@newsread3.dircon.co.uk...
> Jakob <asd@ds.aw> wrote:
> > Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
> > news:383403e4_1@newsread3.dircon.co.uk...
> >> Jakob <asd@ds.aw> wrote:
> >> > Hi All.
> >> >
> >> > I've got a small, but annoying problem.
> >> >
> >> > I need to output a string, and then update the string but keep the
string on
> >> > the
> >> > same line. Ie I need to update the status field contained within the
> > string.
> >> > Please bear in mind that this is NOT a Tk script.
> >> >
> >> > Anybody got a good suggestion ?
> >> >
> >>
> >> E.G :
> >>
> >> $| = 1;
> >> for ( 1 ... 1000 )
> >> {
> >> print "\b\b\b\b";
> >> printf "%.4d",$_;
> >> sleep 1;
> >> }
> >>
> >> Alternatively you might look at Term::Cap, Term::Screen or Curses
modules
> >> from CPAN <http://www.cpan.org>
> >>
>
> > Yeah, sort of but that does'nt really do it.
> >
> > First of all, I tried that approach first, but it deosnt generate any
output
> > at all !
> >
>
> Er thats why it has $| = 1; in it - I bet you didnt try it .
>
> > Second : The length of the updated field might vary, so what I
> > would prefer is to re-write the whole string that contains the
> > update field.
> >
>
> Then get the length of the string first and then use that many backspaces.
>
> You obviously failed to read my suggestion to use Term::Cap or
Term::Screen;
>
> require Term::Screen;
>
> $scr = new Term::Screen;
> unless ($scr) { die " Something's wrong \n"; }
> $scr->clrscr();
> for ( 1...1000)
> {
> $scr->at(5,3)->bold()->puts(sprintf("%.4d",$_))->normal();
> sleep 1;
> }
>
> /J\
> --
> "The teenage masturbators of today are the television executives of
> tomorrow" - Melissa Cabriolet, Drop the Dead Donkey
------------------------------
Date: Thu, 18 Nov 1999 22:14:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Keeping string on same line
Message-Id: <4T_Y3.82$eR.2075@nsw.nnrp.telstra.net>
On Thu, 18 Nov 1999 14:31:29 +0100,
Jakob <asd@ds.aw> wrote:
> I need to output a string, and then update the string but keep the
> string on the same line. Ie I need to update the status field
> contained within the string. Please bear in mind that this is NOT a
> Tk script.
I normally use the "\r" for that. I have no idea how portable that is
between terminal types, though. Make sure you have buffering switched
off, because output buffers to terminals normally get flushed on a
newline only (see the $| variable in perlvar).
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Thu, 18 Nov 1999 09:42:26 -0700
From: "Chris Koharik" <koharikNOSPAM4ME@earthlink.net>
Subject: Re: Keeping string on same line
Message-Id: <811a7m$p16$1@ash.prod.itd.earthlink.net>
Jakob <asd@ds.aw> wrote in message news:8113kj$s08@sdaw04.seinf.abb.se...
> Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
> news:38340ddc_1@newsread3.dircon.co.uk...
> > Jakob <asd@ds.aw> wrote:
> > > Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
> > > news:383403e4_1@newsread3.dircon.co.uk...
> > >> Jakob <asd@ds.aw> wrote:
> > >> > Hi All.
> > >> >
> > >> > I've got a small, but annoying problem.
> > >> >
> > >> > I need to output a string, and then update the string but keep the
> string on
> > >> > the
> > >> > same line. Ie I need to update the status field contained within
the
> > > string.
> > >> > Please bear in mind that this is NOT a Tk script.
> > >> >
> > >> > Anybody got a good suggestion ?
<SNIP>
> Geez, what's with the people on this forum. You're always clankin in
newbies
> asking
> questions.
>
> YES. I did try youre small bit of code, and it didnt do any difference.
>
> Second, I have'nt installed the module yet. I will but I really would
like
> to
> do this with the standard perl dist.
>
> Anyway, thanks for your reply.
If you are just looking to keep the output on the same line and update it (a
line or record counter for instance) then you could print a \r at the end of
the line. If you are wanting to print it at a specific place on the screen
then I don't know of any way in the regular dist to do it.
Cheers,
-Chris
------------------------------
Date: 18 Nov 1999 08:53:25 GMT
From: jaakko.puurunen@_iki . fi (Jaakko Puurunen)
Subject: legal names and about sorting
Message-Id: <slrn837fbs.bh7.jaakko.puurunen@cimpc199.cimcorp.fi>
Hello everybody!
Ok, the text is a bit long but I hope to make myself understood by one
posting.
I've been writing programs that automate some tasks in our electrical
design docementation, i.e. programs that produce drawings automatically
based on information is drawings and Oracle database.
I typically operate with devices that are named like +LOCATION-DESIGNATION
where LOCATION is e.g. R1, R2.1 or C1 etc and DESIGNATION A1.0 or S00115
which means that the complete name for a device could e.g. be +C1-A1.0
(a PLC IO-card on control cabinet C1).
What I do with these devices is that I create an array for each device
that I'm working with. This far I've named that arrays so that I remove
the + from the name first because I thought it was not a valid character
for the array (as Learning Perl states the names begin with a letter).
I have not been able to directly produce an array with the debugger that
would begin with the + sign (and I've tried quite a few options which
all fail due to different errors).
Yesterday I noticed that by first defining a variable for the device
($a = '+C1-A1') and then using that to create an array (@$a = (1,2,3)),
it passes.
I think this is all very fine because I would not need to strip to +
anymore but since I don't feel very sure it's safe I'd like to hear
some comments first.
So, can I use this feature without fearing that my programs will
be unusable in the future?
Then another question about sorting: let's say that I have the following
list of devices:
+CV54-BM103.13
+CV72.3-B102.20
+CV43.1-B103.5
+CV43.4-B103.10
+CV73.2-B103.18
+CV82.1-B102.3
+CV42.1-B102.5
I would like to sort this list by the bus number where the bus number is
the number after the - and the letters. The bus would in the first line
then be 103 and in the last line 102. Numbers after the dot represent
the number of that device on that specific bus (the device on the first
line would then be device #13 on bus #103).
The following program is what I'm using now to sort these but I does
not sort the devices (after the dot) numerically (it does sort them
correctly by the bus).
#!/usr/bin/perl -w
open (FILE, "1.txt"); @a = <FILE>; close FILE;
chomp @a;
@b = sort by_asi_bus @a;
for (@b) { print "$_\n" }
sub by_asi_bus {
@alist = (split (/-\D+/, $a))[-1];
@blist = (split (/-\D+/, $b))[-1];
return $alist[$#alist] <=> $blist[$#blist];
} # end of by_asi_bus
If the data after splitting are treated as numbers shouldn't the above
program return them sorted in numberical order? The following is what I
get now:
+CV72.3-B102.20
+CV82.1-B102.3
+CV42.1-B102.5
+CV43.4-B103.10
+CV54-BM103.13
+CV73.2-B103.18
+CV43.1-B103.5
I'd be very happy if somebody could point me to the right direction
about this (the above sorting is adapted from FMTEYEWTK/sorting). I've
pretty much spent all my (limited :) resources on this one (and I think
it shouldn't be that difficult).
Thanks in advance!
Jaska
Please note: if you plan to send e-mail to me remove underscore and
spaces from e-mail address.
------------------------------
Date: 18 Nov 1999 11:53:36 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: legal names and about sorting
Message-Id: <slrn837q6v.1qp.mgjv@wobbie.heliotrope.home>
On 18 Nov 1999 08:53:25 GMT,
Jaakko Puurunen <jaakko.puurunen@_iki.fi> wrote:
> Yesterday I noticed that by first defining a variable for the device
> ($a = '+C1-A1') and then using that to create an array (@$a = (1,2,3)),
> it passes.
You are doing evil things. If you don't understand why, you shouldn't
even be contemplating it.
What you want is a hash with array references.
# perldoc perlref
# perldoc perllol
# perldoc perldsc
> I think this is all very fine because I would not need to strip to +
> anymore but since I don't feel very sure it's safe I'd like to hear
> some comments first.
Well, you;ve heard mine :) I'm sure other people will also urge you not
to meddle with this sort of thing.
> So, can I use this feature without fearing that my programs will
> be unusable in the future?
Probably you can. But that's not the point. The point is that you're
stumbling around in the dark in a place where you shouldn't really be
anymore since the release of perl 5. It's a dangerous place. It's a
place where it's hard to find bugs.
I would advise you to run all your programs with the -w flag, and
especially with the strict pragma (as in 'use strict;'), because that
will tell you you're doing something you shouldn't do.
> Then another question about sorting: let's say that I have the following
> list of devices:
>
> +CV54-BM103.13
> +CV72.3-B102.20
> +CV43.1-B103.5
> +CV43.4-B103.10
> +CV73.2-B103.18
> +CV82.1-B102.3
> +CV42.1-B102.5
>
> I would like to sort this list by the bus number where the bus number is
> the number after the - and the letters.
You'll have to unravel it, and sort the unravelled bits.
You could probably use one of the packed sorts (Have you guys finally
decided on a name?) that Uri and Larry have successfully been
talking about for a while now. Or you could use a Schwartzian transform.
I'll leave it up to you to find www.deja.com and to type in
~g comp.lang.perl.misc & sort
In the search box. Read a few messages.
I'll leave it up to Larry to come up with the fastest method :)
Martien
--
Martien Verbruggen |
Interactive Media Division | The gene pool could use a little
Commercial Dynamics Pty. Ltd. | chlorine.
NSW, Australia |
------------------------------
Date: 18 Nov 1999 13:59:35 GMT
From: jaakko.puurunen@_iki . fi (Jaakko Puurunen)
Subject: Re: legal names and about sorting
Message-Id: <slrn83819v.bh7.jaakko.puurunen@cimpc199.cimcorp.fi>
On 18 Nov 1999 11:53:36 GMT, Martien Verbruggen <mgjv@wobbie.heliotrope.home>
wrote:
>You are doing evil things. If you don't understand why, you shouldn't
>even be contemplating it.
Whatever you say man ... I'll have to look "contemplating" from the
dictionary first.
>What you want is a hash with array references.
>
># perldoc perlref
># perldoc perllol
># perldoc perldsc
Ok, I'll look into these.
>Probably you can. But that's not the point. The point is that you're
>stumbling around in the dark in a place where you shouldn't really be
>anymore since the release of perl 5. It's a dangerous place. It's a
>place where it's hard to find bugs.
I started learning perl from version 5 and I've worked my way learning
the things I need at that point. So I guess I need to look at the
array references at this time.
>I would advise you to run all your programs with the -w flag, and
>especially with the strict pragma (as in 'use strict;'), because that
>will tell you you're doing something you shouldn't do.
I have the 'use strict' in my code but it's commented out because it
complains too much :) Warnings from -w I do check and fix.
>You'll have to unravel it, and sort the unravelled bits.
To the dictionary again ...
>You could probably use one of the packed sorts (Have you guys finally
>decided on a name?) that Uri and Larry have successfully been
>talking about for a while now. Or you could use a Schwartzian transform.
>I'll leave it up to you to find www.deja.com and to type in
>
>~g comp.lang.perl.misc & sort
>
>In the search box. Read a few messages.
Ok, many thanks for the prompt reply.
Jaska
------------------------------
Date: Thu, 18 Nov 1999 10:19:20 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: legal names and about sorting
Message-Id: <x3yogcrzv2f.fsf@tigre.matrox.com>
jaakko.puurunen@_iki . fi (Jaakko Puurunen) writes:
> What I do with these devices is that I create an array for each device
> that I'm working with. This far I've named that arrays so that I remove
> the + from the name first because I thought it was not a valid character
> for the array (as Learning Perl states the names begin with a letter).
>
> I have not been able to directly produce an array with the debugger that
> would begin with the + sign (and I've tried quite a few options which
> all fail due to different errors).
Don't do that. This is not the best way to do things. Read below.
> Yesterday I noticed that by first defining a variable for the device
> ($a = '+C1-A1') and then using that to create an array (@$a = (1,2,3)),
> it passes.
Yes. This is called symbolic referencing. In most cases though, you
shouldn't be using this feature. A better approach is discussed in the
FAQs.
> I think this is all very fine because I would not need to strip to +
> anymore but since I don't feel very sure it's safe I'd like to hear
> some comments first.
>
> So, can I use this feature without fearing that my programs will
> be unusable in the future?
I don't see why your programs should become unusable in the future,
but as I said, this is not what you want to do. It is better for you
to use a hash. The keys of the hash would be the device names, and the
values would be the corresponding arrays. Example:
my %hash;
my $device = '+C1-A1';
$hash{$device} = [1, 2, 3];
Now, to access, say, the 2nd element of the array corresponding to
$device, you would use:
$hash{$device}[1]
This approach is much cleaner. If you don't know much about Perl's
complex data structures, checkout:
perlref
perldsc
perllol
> Then another question about sorting: let's say that I have the following
> list of devices:
>
> +CV54-BM103.13
> +CV72.3-B102.20
> +CV43.1-B103.5
> +CV43.4-B103.10
> +CV73.2-B103.18
> +CV82.1-B102.3
> +CV42.1-B102.5
>
> I would like to sort this list by the bus number where the bus number is
> the number after the - and the letters. The bus would in the first line
> then be 103 and in the last line 102. Numbers after the dot represent
> the number of that device on that specific bus (the device on the first
> line would then be device #13 on bus #103).
I don't understand what you want to do exactly. So I'll let someone
else help you there.
HTH,
--Ala
------------------------------
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 1421
**************************************