[19182] in Perl-Users-Digest
Perl-Users Digest, Issue: 1377 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 25 14:10:37 2001
Date: Wed, 25 Jul 2001 11:10:11 -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: <996084611-v10-i1377@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 25 Jul 2001 Volume: 10 Number: 1377
Today's topics:
sprintf <strawman@plexi.com>
Re: sprintf <curtish@ourtownusa.net>
Re: sprintf <godzilla@stomp.stomp.tokyo>
stumped on make of B.sl <maurice_lampell@agilent.com>
Substitute _last_ occurrece in string? (Paul Moloney)
Re: Substitute _last_ occurrece in string? <weiss@kung.foo.at>
Re: Substitute _last_ occurrece in string? <godzilla@stomp.stomp.tokyo>
Re: Substitute _last_ occurrece in string? <mbudash@sonic.net>
Re: Substitute _last_ occurrece in string? <godzilla@stomp.stomp.tokyo>
Re: Substitute _last_ occurrece in string? (Craig Berry)
Using Perl to change variable length in an MS Access .M (Razvan Mihailescu)
Re: Using Perl to change variable length in an MS Acces <jeff@vpservices.com>
Where are the values stored? <nospam.jonni@ifm.liu.se>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 25 Jul 2001 12:30:16 -0400
From: Edward Little Titan/SRC x4621 <strawman@plexi.com>
Subject: sprintf
Message-Id: <3B5EF418.8011B9DD@plexi.com>
How can I print a floating point number with leading zeros?
I've tried:
$number = sprintf("%2.3f",$number);
print "$number\n";
with no luck. I've also tried:
$number = sprintf("%02.3f",$number);
Thanks for any help.
------------------------------
Date: Wed, 25 Jul 2001 11:38:14 -0500
From: "Curtis Hawthorne" <curtish@ourtownusa.net>
Subject: Re: sprintf
Message-Id: <jAC77.38$1K.265@newsfeed.slurp.net>
To print leading 0's, you'll need something like sprint("%08.3f", $number);
where 8 is the total number of digits in the output (including the decimal
point) and 3 is the number of digits behind the decimal.
Curtis H.
"Edward Little Titan/SRC x4621" <strawman@plexi.com> wrote in message
news:3B5EF418.8011B9DD@plexi.com...
>
>
>
> How can I print a floating point number with leading zeros?
>
> I've tried:
>
> $number = sprintf("%2.3f",$number);
> print "$number\n";
>
> with no luck. I've also tried:
>
> $number = sprintf("%02.3f",$number);
>
>
>
>
> Thanks for any help.
>
------------------------------
Date: Wed, 25 Jul 2001 11:02:35 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: sprintf
Message-Id: <3B5F09BB.25AAA9D1@stomp.stomp.tokyo>
Curtis Hawthorne wrote:
> Edward Little Titan/SRC x4621 wrote:
> > How can I print a floating point number with leading zeros?
(snipped)
> To print leading 0's, you'll need something like sprint("%08.3f", $number);
> where 8 is the total number of digits in the output (including the decimal
> point) and 3 is the number of digits behind the decimal.
Use of sprint("%08.3f", $number); will cause a script
to crash by calling a non-existent sub-routine.
Use of sprintf("%08.3f", $number); will not lead pad a zero.
$number = sprintf("%08.3f", $number);
print $number;
Godzilla!
------------------------------
Date: Wed, 25 Jul 2001 09:25:19 -0400
From: Maurice Lampell <maurice_lampell@agilent.com>
Subject: stumped on make of B.sl
Message-Id: <3B5EC8BF.3440681D@agilent.com>
Hello there,
I'm in the middle of a perl install on a 712/60 workstation running UX
10.20. I've gotten as fars as building perl, miniperl and libperl.a, but
am getting stumped below. Any ideas on how to proceed would be
appreciated!
Thanks,
Maurice Lampell
Agilent Technologies
# make
AutoSplitting perl library
./miniperl -Ilib -e 'use AutoSplit; \
autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm
./miniperl minimod.pl > minimod.tmp
sh mv-if-diff minimod.tmp lib/ExtUtils/Miniperl.pm
File lib/ExtUtils/Miniperl.pm not changed.
Making DynaLoader (static)
Making utilities
Making x2p stuff
Making B (dynamic)
rm -f ../../lib/auto/B/B.sl
LD_RUN_PATH="" ld -shared -L/usr/local/lib -L/opt/gnu/lib B.o
-o ../..
/lib/auto/B/B.sl
ld: (Warning) Can't hide symbol "ared"
ld: Unsatisfied symbols:
PL_na (data)
Perl_sv_2pv (code)
Perl_sv_setsv (code)
Perl_newCONSTSUB (code)
Perl_sv_setiv (code)
PL_compcv (data)
Perl_warn (code)
PL_curpad (data)
PL_initav (data)
Perl_newSVpvn (code)
Perl_sv_2nv (code)
Perl_sv_catpvn (code)
Perl_newRV (code)
Perl_mg_set (code)
perl_call_method (code)
strncmp (code)
Perl_sv_setpvn (code)
strcmp (code)
Perl_sv_setnv (code)
Perl_gv_stashpvn (code)
Perl_newSVrv (code)
Perl_av_push (code)
perl_get_sv (code)
PL_endav (data)
PL_sv_yes (data)
Perl_sv_2iv (code)
PL_stack_base (data)
Perl_mg_size (code)
PL_op_desc (data)
Perl_stack_grow (code)
perl_get_av (code)
Perl_form (code)
Perl_sv_newmortal (code)
Perl_sv_catpv (code)
Perl_sv_mortalcopy (code)
PL_main_start (data)
Perl_sv_setpv (code)
PL_stack_max (data)
PL_sv_undef (data)
Perl_croak (code)
sprintf (code)
PL_op_name (data)
Perl_sv_2bool (code)
Perl_sv_2mortal (code)
Perl_sv_setuv (code)
Perl_newXS (code)
Perl_markstack_grow (code)
PL_main_cv (data)
PL_markstack_ptr (data)
PL_minus_c (data)
PL_maxo (data)
Perl_hv_iterinit (code)
PL_beginav_save (data)
Perl_hv_iternextsv (code)
PL_markstack_max (data)
PL_stack_sp (data)
PL_sv_no (data)
PL_amagic_generation (data)
PL_main_root (data)
PL_opargs (data)
PL_op (data)
Perl_gv_fetchfile (code)
Perl_newSVpv (code)
Perl_newSViv (code)
ld: No $UNWIND_END$ subspace has been defined (probably missing
/usr/ccs/lib/crt
0.o)
*** Error exit code 1
Stop.
*** Error exit code 1
Stop.
#
------------------------------
Date: 25 Jul 2001 07:00:23 -0700
From: paul_moloney@hotmail.com (Paul Moloney)
Subject: Substitute _last_ occurrece in string?
Message-Id: <b917d6bd.0107250600.7be67f79@posting.google.com>
How can I substitute the last occurence of a certain text string within
a string?
For instance, if I have the string $string = "abcdefghiajkl", I'd
like to be able to substitute the last "a" in $string with null so that
I'm returned "abcdefghijkl".
Is there an argument I can pass to the usual substitute
operator? For example:
$string =~ s/a//<ARGUMENT>
or is there a more lengthy way to do it? Thanks,
P.
------------------------------
Date: Wed, 25 Jul 2001 18:11:43 +0200
From: "Stefan Weiss" <weiss@kung.foo.at>
Subject: Re: Substitute _last_ occurrece in string?
Message-Id: <3b5eef0d$1@e-post.inode.at>
"Paul Moloney" <paul_moloney@hotmail.com> wrote:
> How can I substitute the last occurence of a certain text string within
> a string?
>
> For instance, if I have the string $string = "abcdefghiajkl", I'd
> like to be able to substitute the last "a" in $string with null so that
> I'm returned "abcdefghijkl".
use a zero-width negative look-ahead:
$string = "abcadefaghiajkl";
$string =~ s/a(?!.*a)//;
print $string. "\n";
# prints abcadefaghijkl
cheers,
stefan
------------------------------
Date: Wed, 25 Jul 2001 09:33:57 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Substitute _last_ occurrece in string?
Message-Id: <3B5EF4F5.3C967C79@stomp.stomp.tokyo>
Paul Moloney wrote:
> How can I substitute the last occurence of a certain text string within
> a string?
> For instance, if I have the string $string = "abcdefghiajkl", I'd
> like to be able to substitute the last "a" in $string with null so that
> I'm returned "abcdefghijkl".
> Is there an argument I can pass to the usual substitute
> operator? For example:
(snipped)
Use of index () and substr () will prove to be
very efficient for this task.
if (index ($string, $remove) > -1)
This line checks for the existence of
a character or sub-string to be removed.
$check = index ($string, $remove);
$check2 = rindex ($string, $remove);
if ($check2 > $check)
Those three lines check for more than
one instance of what is to be removed.
My substr () following those lines
performs the actual substitution.
Use of a purely regex method which performs
the same functions will invoke a memory wasteful
regex engine whether it is needed or not.
This is quite inefficient.
Godzilla!
--
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
$string = "abcdefghiajkl";
$remove = "a";
if (index ($string, $remove) > -1)
{
$check = index ($string, $remove);
$check2 = rindex ($string, $remove);
if ($check2 > $check)
{ substr ($string, $check2, length ($remove), ""); }
}
print $string;
exit;
PRINTED RESULTS:
________________
abcdefghijkl
------------------------------
Date: Wed, 25 Jul 2001 17:04:21 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Substitute _last_ occurrece in string?
Message-Id: <mbudash-89A3AA.10042325072001@news.sonic.net>
In article <3b5eef0d$1@e-post.inode.at>, "Stefan Weiss"
<weiss@kung.foo.at> wrote:
> "Paul Moloney" <paul_moloney@hotmail.com> wrote:
>
> > How can I substitute the last occurence of a certain text string within
> > a string?
> >
> > For instance, if I have the string $string = "abcdefghiajkl", I'd
> > like to be able to substitute the last "a" in $string with null so that
> > I'm returned "abcdefghijkl".
>
> use a zero-width negative look-ahead:
>
> $string = "abcadefaghiajkl";
> $string =~ s/a(?!.*a)//;
> print $string. "\n";
>
> # prints abcadefaghijkl
>
just for fun, you could also take advantage of the RE engine's right to
left operation:
$rev = reverse($string);
$rev =~ s/a//;
$string = reverse($rev);
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Wed, 25 Jul 2001 10:23:39 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Substitute _last_ occurrece in string?
Message-Id: <3B5F009B.BBDAEDD3@stomp.stomp.tokyo>
Michael Budash wrote:
> Stefan Weiss"
> > Paul Moloney wrote:
> > > How can I substitute the last occurence of a certain text string within
> > > a string?
> > > For instance, if I have the string $string = "abcdefghiajkl", I'd
> > > like to be able to substitute the last "a" in $string with null so that
> > > I'm returned "abcdefghijkl".
(snipped)
> just for fun, you could also take advantage of the RE engine's right to
> left operation:
> $rev = reverse($string);
> $rev =~ s/a//;
> $string = reverse($rev);
Will this work correctly for a single instance of
letter "a" within string? This is, a string only
contains one letter a and parameters are to remove
the "last instance" of this letter. Think on this.
Godzilla!
------------------------------
Date: Wed, 25 Jul 2001 17:33:17 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Substitute _last_ occurrece in string?
Message-Id: <tlu0mt91k35j3a@corp.supernews.com>
Paul Moloney (paul_moloney@hotmail.com) wrote:
: How can I substitute the last occurence of a certain text string within
: a string?
:
: For instance, if I have the string $string = "abcdefghiajkl", I'd
: like to be able to substitute the last "a" in $string with null so that
: I'm returned "abcdefghijkl".
I typically use negative lookahead:
s/a(?!.*a)//;
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Brute force done fast enough looks slick."
| - William Purves
------------------------------
Date: 25 Jul 2001 08:45:10 -0700
From: razvan.mihailescu@gartner.com (Razvan Mihailescu)
Subject: Using Perl to change variable length in an MS Access .MDB file
Message-Id: <451d8b00.0107250745.7d026760@posting.google.com>
Hi - I know this may be a shot in the dark, but I figured why not try
Google.
I want to open up an .mdb file with Perl and reduce the variable
length on all variables that are 8+ characters. I need to import the
.mdb file into SPSS and SPSS only accepts vars that are <= 8
characters.
Has anyone out there done anything like this?
I'm new to Perl, so please don't get into rocket science :)
Thank you in advance, Razvan. (Portland, OR)
------------------------------
Date: Wed, 25 Jul 2001 09:12:01 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Using Perl to change variable length in an MS Access .MDB file
Message-Id: <3B5EEFD1.84A1D53C@vpservices.com>
Razvan Mihailescu wrote:
>
> I want to open up an .mdb file with Perl and reduce the variable
> length on all variables that are 8+ characters. I need to import the
> .mdb file into SPSS and SPSS only accepts vars that are <= 8
> characters.
The DBD::ODBC or DBD::ADO modules will give you full access to the data
and you can use a SQL update statement combined with a simple perl s///
to do what you want. (Or possibly also do it all in the update statement
with a SQL substr() ).
> Thank you in advance, Razvan. (Portland, OR)
You're welcome in hindsight, Jeff. (also Portland, OR)
--
Jeff
------------------------------
Date: Wed, 25 Jul 2001 16:38:04 +0200
From: "Jonas Nilsson" <nospam.jonni@ifm.liu.se>
Subject: Where are the values stored?
Message-Id: <9jmleg$h7l$1@newsy.ifm.liu.se>
Try this:
use Data::Dumper;
my %hash;
$hash{'A'} = "First value";
print Dumper(\%hash);
$hash{'A'}->{'B'} = "Second value";
print Dumper(\%hash);
print $hash{'A'}->{'B'};
RESULT:
$VAR1 = {
'A' => 'First value'
};
$VAR1 = {
'A' => 'First value'
};
Second value
Where is the value "Second value" shown in the output stored? It isn't in
%hash as shown by Dumper. Still it appears in the printout.
I know that use strict; tells you something like: Can't use string ("First
value") as a HASH ref while "strict refs" in use at D:\Slask\clpm002.pl line
6.
/jN
------------------------------
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 1377
***************************************