[18683] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 851 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 7 21:06:58 2001

Date: Mon, 7 May 2001 18:05:08 -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: <989283907-v10-i851@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 7 May 2001     Volume: 10 Number: 851

Today's topics:
        Base 6 sieve. (Abigail)
    Re: How to determine file type of a filehandle? (Clinton A. Pierce)
        how to set binary mode when uploading a file (R.S.)
    Re: Newbie LWP Question <tinamue@zedat.fu-berlin.de>
        Newbie Perl 5 - checking 2 form elements <paanwa@hotmail.com>
    Re: Newbie Perl 5 - checking 2 form elements <carlos@plant.student.utwente.nl>
    Re: Newbie Perl 5 - checking 2 form elements <centreman_19@NOSPAMyahoo.com>
    Re: Newbie Perl 5 - checking 2 form elements (Craig Berry)
    Re: Newbie Perl 5 - checking 2 form elements <mischief@velma.motion.net>
        PL/SQL and DBI. <Ming.Zhang@ti.com>
    Re: redirect to a url & avoiding hacks <godzilla@stomp.stomp.tokyo>
    Re: redirect to a url & avoiding hacks <flavell@mail.cern.ch>
    Re: redirect to a url & avoiding hacks <gasper@cis.ohio-state.edu>
    Re: redirect to a url & avoiding hacks (Craig Berry)
    Re: redirect to a url & avoiding hacks <godzilla@stomp.stomp.tokyo>
    Re: Simple Regex for URL to Filename (BUCK NAKED1)
    Re: Simple Regex <mischief@velma.motion.net>
    Re: Sort String <uri@sysarch.com>
    Re: Sort String <tinamue@zedat.fu-berlin.de>
    Re: Sort String <djm@spamfree.mcoe.k12.ca.us>
    Re: Sort String (Craig Berry)
    Re: Sort String <krahnj@acm.org>
    Re: Trying to fill in a Pager Web page. <ramseyk@home.com>
        Unreasonable conversion . ERROR ORA-001460 <tfurnitu@cisco.com>
        using DBI,unreasonable conversion error-ORA 01460 <tfurnitu@cisco.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 8 May 2001 00:13:39 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Base 6 sieve.
Message-Id: <slrn9feehj.t91.abigail@tsathoggua.rlyeh.net>


As Anno pointed out yesterday, a sieve based on a base 6 numbering
system uses less memory. Here's an implementation, which is hopefully
reasonable efficient.


#!/opt/perl/bin/perl -l

# A sieve based on base 6. Only possible primes are those numbers p
# for which p mod 6 == 1, or p mod 6 == 5.
# 
# Let n = 6 * k + l (0 <= l < 6). Then the bit b associated with n is
# b = 2 * k + [undef, 0, undef, undef, undef, 1] -> [l]
# In reverse, given a bit b, the corresponding number n is
# n = 6 * int (b / 2) + [1, 5] -> [b % 2].

use strict;
use warnings 'all';

sub scrub    ($);
sub findnext ($);

my $max   = $ARGV [0] || 1000;

my @PRIMES    = (2, 3);
my $BASE      =  6;     # LCM of @PRIMES.
my $BITS_BASE =  2;
my $BITS_BYTE =  8;

my $bits  = $BITS_BASE * int ($max / $BASE) + ($max % $BASE ? $BITS_BASE : 0);
my $bytes = int ($bits / $BITS_BYTE) + ($bits % $BITS_BYTE ? 1 : 0);
my $sieve = "\xFF" x $bytes;

# Numbers less than the base are special.
foreach my $prime (@PRIMES) {
    print $prime
}

my $i = 5;

for (; $i && $i <= sqrt ($max); $i = findnext $i) {
    print $i;
    scrub $i;
}

# Would be nice if we could eliminate the '&& $i <=' test.
# Perhaps when initializing the sieve?
for (; $i && $i <=       $max ; $i = findnext $i) {
    print $i;
}

exit;

my ($offset1, $offset2);
INIT {
    $offset1 = [undef, 0, undef, undef, undef, 1];
    $offset2 = [1, 5];
}

# Scrub out all multiples of the given argument. It's easy to see that
# all multiples less than the square already have been crossed out, and
# we only have to scrub out the odd multiples.
# This sub uses magic constants 2, 3 and 4. Should be eliminated.
sub scrub ($) {
    use integer;
    my $n = shift;
    my $m = $n;

    # Make it so it's synchronized with the main loops logic.
    if ($m % 3 == 1) {
        my $c = $n * $m;
        vec ($sieve, $BITS_BASE * ($c / $BASE) + $offset1 -> [$c % $BASE],
                     1) = 0;
        $m += 4;
    }
    
    my $limit = $max - $BASE * $n;
    my $c     = $n * $m;

    # Core loop, we want to minimize on conditionals here.
    while ($c <= $limit) {
        vec ($sieve, $BITS_BASE * ($c / $BASE) + $offset1 -> [$c % $BASE],
                     1) = 0;
        $c += 2 * $n;
        vec ($sieve, $BITS_BASE * ($c / $BASE) + $offset1 -> [$c % $BASE],
                     1) = 0;
        $c += 4 * $n;
    }

    # Basically a copy of the previous loop, but with extra checks.
    # Check don't hurt now as this loop is performed only once.
    {
        last if $c > $max;
        vec ($sieve, $BITS_BASE * ($c / $BASE) + $offset1 -> [$c % $BASE],
                     1) = 0;
        $c += 2 * $n;
        last if $c > $max;
        vec ($sieve, $BITS_BASE * ($c / $BASE) + $offset1 -> [$c % $BASE],
                     1) = 0;
        $c += 4 * $n;
    }

}

# Find the next prime number after the given number.
sub findnext ($) {
    use integer;
    my $n = shift;
    my $i = $BITS_BASE * ($n / $BASE) + $offset1 -> [$n % $BASE] + 1;
    while ($i <= $bits) {
        if (vec ($sieve, $i, 1)) {
            return $BASE * ($i / $BITS_BASE) + $offset2 -> [$i % $BITS_BASE]
        }
        $i ++
    }
    undef;
}


__END__
-- 
#!/opt/perl/bin/perl   --   # Remove trailing newline!
BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJ


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

Date: Mon, 07 May 2001 23:24:35 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: How to determine file type of a filehandle?
Message-Id: <T8GJ6.3398$V5.393900@news1.rdc1.mi.home.com>

[Posted and mailed]

Your original requirements were how to determine if a filehandle was a socket,
interactive or a file on disk.

To weed out the sockets, try doing uniquely socket-ish things to it:

	$sock=IO::Socket::INET->new(Proto => 'tcp', PeerAddr => 'foo',
		PeerPort=> '80');
	die unless $sock;
	$peer=getpeername($sock);
	die "Not a socket" unless $peer;  

Normal filehandles bomb at this.  I believe the -S test that you were 
pointed to isn't going to work under Windows.  This works fine.

More importantly, I think that a design that either

	A. Cares about what kind of device you're talking to
	   (socket, tty, pipe, file, etc...)

	-or-

	B. Has an open filehandle, but has no idea what it's 
	   connected to.

Is probably somewhat wrongheaded to begin with.


-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Tue, 08 May 2001 00:21:56 GMT
From: rastacey@roadrunner.nf.net (R.S.)
Subject: how to set binary mode when uploading a file
Message-Id: <3af738d8.566198320@news.thezone.net>

I am trying to upload an image file (jpg) using 
print $query->filefield(-name=>'photo'.-default=>'starting
value',-size=>50,-maxlength=>80);

And then save the fiel uaing
open(OUTFILE,">pics\\photo.jpg")
while ($bytesread=read($fileH1,$buffer,1024)) {
print OUTFILE $buffer:
}

This works as far as uploading the file but there always seem to be
too many characters.
I have lookaed at buffer, binary, headers without fixing this problem.

Any help or a pointer to a sample would be appreciated. 




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

Date: 7 May 2001 22:23:39 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Newbie LWP Question
Message-Id: <9d779b$h44c7$3@fu-berlin.de>

hi,
Jean <jean.zoch@utoronto.ca> wrote:

> I've been using LWP::Simple to get the HTML code from a website. To do this
> I use:

> $url = http://the.url.iwant;

> use LWP::Simple;

> $content = get($url);

> I also, however, need the actual URL of the page. Since many pages have
> redirects, the URL of the content I get is often not my $url. I thought
> maybe I could get the actual URL using the 'head' command, but this does not
> return it.

well, you *could* do
print  $res->{_previous}->{_headers}->{location};

> Any suggestions? Perhaps I need to use a different Module?

perldoc LWP::UserAgent (simple_request())

hth,
tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Mon, 7 May 2001 18:30:25 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Newbie Perl 5 - checking 2 form elements
Message-Id: <tfe8ga79n5mjb0@corp.supernews.com>

How do I correct the following script?  I am trying to evaluate the contents
of 2 form elements for equality.

#############
(snip)

$Email1=param('email');
$Email2=param('email2');


if (($Email1 eq "$Email2") && (param('email') ne "")
{do something;}
else {do something else;}

##############

PAW




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

Date: Tue, 8 May 2001 00:59:18 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Newbie Perl 5 - checking 2 form elements
Message-Id: <9d7955$n8b$1@dinkel.civ.utwente.nl>

if ((param('email') =~ /\@.*\./)&&(param('email2') eq param('email') )) {
    do something
else {
    do something else
}


"PaAnWa" <paanwa@hotmail.com> wrote in message
news:tfe8ga79n5mjb0@corp.supernews.com...
> How do I correct the following script?  I am trying to evaluate the
contents
> of 2 form elements for equality.
>
> #############
> (snip)
>
> $Email1=param('email');
> $Email2=param('email2');
>
>
> if (($Email1 eq "$Email2") && (param('email') ne "")
> {do something;}
> else {do something else;}
>
> ##############
>
> PAW
>
>




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

Date: Mon, 7 May 2001 15:51:36 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: Newbie Perl 5 - checking 2 form elements
Message-Id: <9d7970$rib$1@fremont.ohsu.edu>

On first glance, shouldn't you get rid of the quotes around $Email2 in the
if statement?




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

Date: Mon, 07 May 2001 23:24:44 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Newbie Perl 5 - checking 2 form elements
Message-Id: <tfeblso8gofk92@corp.supernews.com>

PaAnWa (paanwa@hotmail.com) wrote:
: How do I correct the following script?  I am trying to evaluate the contents
: of 2 form elements for equality.
: 
: $Email1=param('email');
: $Email2=param('email2');
: 
: if (($Email1 eq "$Email2") && (param('email') ne "")

The quotes around "$Email2" are meaningless.  Using the function call to
grab param 'email' rather than reusing the convenience variable $Email1
seems odd.  This isn't your actual code, as the parens don't balance. 

Other than that, this should work. If it the test is failing, either the
values differ or they are both empty strings. 

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Mon, 07 May 2001 23:28:24 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Newbie Perl 5 - checking 2 form elements
Message-Id: <tfebso59ihfue8@corp.supernews.com>

In comp.lang.perl.misc PaAnWa <paanwa@hotmail.com> wrote:
> How do I correct the following script?  I am trying to evaluate the contents
> of 2 form elements for equality.

> #############
> (snip)

> $Email1=param('email');
> $Email2=param('email2');

Count the left parens in the next line. There are four.
Count the right parens in the enxt line. There are three.

> if (($Email1 eq "$Email2") && (param('email') ne "")


    if ( ( $Email1 eq $Email2 ) && ( param('email') ne '' ) )


> {do something;}
> else {do something else;}

Also, you don't need to re-evaluate param('email') in your
conditional, since it's in a variable.

    if ( ( $Email1 eq $Email2 ) && $Email1 )


Use whitspace. It is your friend.

Chris

-- 
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty.  -- Mohandas K. Gandhi



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

Date: Mon, 7 May 2001 18:15:50 -0500
From: "Ming Zhang" <Ming.Zhang@ti.com>
Subject: PL/SQL and DBI.
Message-Id: <9d7ab5$5dt$1@tilde.csc.ti.com>

Does anybody have experience on using DBI with
oracle Pl/SQL?Please give me an example. What should I do if I want to pass
in one variable to PL/SQL and get a returned recordset?
Thanks!




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

Date: Mon, 07 May 2001 15:34:50 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <3AF7230A.979F38A8@stomp.stomp.tokyo>

Tina Mueller wrote:
 
> Alan J. Flavell wrote:
> > Tina Mueller wrote:
 
> >> ok, my suggestions if you wanna avoid using CGI.pm is,
 
> > Normally, my suggestion would be "think again".  But if you really and
> > truly are going to use none of the other tried and tested facilities
> > of CGI.pm in your script, and you're fully acquainted with the
> > relevant details of the specification, then it's OK, I suppose.
 
> >> print at least these three lines:
 
> > Not necessarily, because status 302 is defined to be the default
> > when a Location: response is issued from a parsed-headers script.
> > So it could be left out.
 
> well, this is what CGI.pm does, so it can't be wrong.

Which well explains numerous revisions of CGI.pm over
the years and, ongoing revisions, to correct what it
does do wrong, which is significant, evidenced by the
number of articles posted to USENET inquiring how to
fix what CGI.pm screws up.


> if i had a CGI-script which does nothing more than this
> redirect, I wouldn't use CGI.pm, because then it is overkill.

Then why did you disagree with me? 

* chortles *


> (provided that it is not an nph-script)

A non-parsed headers script is of a type which
is least likely to incorporate CGI.pm for use.
Those of us whom write nph scripts have zero
use for CGI.pm; it serves as a nuisance.


> for anything else a little bit more complex, of course
> i would recommend CGI.pm, too.

Complexiety is unrelated to use of CGI.pm in a script.
This module is a short cut intended to save script
writing time and reduce programming effort, both
of which encourage copy and paste technicians and
discourages learning how to program. CGI.pm is for
copy and paste technicians too lazy to type code.
This is, clearly, one reason for its popularity.

> i responded to the suggestion to use:
> print "Location: url/path";
 
> which shows that not using CGI.pm should not be recommended,
> because it is missing for keystrokes - "\n\n".

Yeah, yeah, I am becoming addled and forgetful. Seems
more gracious to simply point out an error rather than
launch into an idiotic tirade riddled with insults
and outright lies. However, I will concede this type
of behavior is quite the norm for anal retentive
sissified geeks populating so many tech newsgroups.

Your logic is, paraphrased,

"You should use CGI.pm because Godzilla is age addled
 and forgot her double newlines."

* snorts *


> or even more correct, CGI.pm knows better what to
> use for the header end.

Your logic is most laughable.


Godzilla! Queen of The Age Addled.


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

Date: Tue, 8 May 2001 00:16:03 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <Pine.LNX.4.30.0105080009200.30987-100000@lxplus003.cern.ch>


This is still OT, but I still don't like to see partially
misleading answers lying around...

On 7 May 2001, Tina Mueller wrote:

> i responded to the suggestion to use:
> print "Location: url/path";

Which of course is wrong if a redirection is wanted.  For a
redirection, the CGI specification mandates the use of the complete
URL, not merely the absolute URLpath.

> which shows that not using CGI.pm should not be recommended,

;-)

> because it is missing for keystrokes - "\n\n".

That's only the trivial part.  It's wrong because a redirection was
asked for - but specifying a URLpath on a CGI Location: response does
not produce a redirection (the CGI specification mandates the server
to return the result directly, with status 200).

(I have the godzilla troll killfiled anyway - I only see that stuff if
somebody sees fit to quote it).

cheers



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

Date: Mon, 7 May 2001 19:46:38 -0400
From: "Keith G" <gasper@cis.ohio-state.edu>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <9d7c14$e14$1@news.cis.ohio-state.edu>

Sorry to have put everyone into a tizzy! I figured
out the easiest way to do it was to avoid using
Perl to do the redirection and to instead do this:

 .......
print "<script>location.replace(\"http://mypage.com\");</script>\n";
 .......

This seems to work just fine. I'd love to respond
to godzilla's knock about being a 'copy and paste
baby' or needing to 'learn how to program,' but
i've got more important things to concentrate on.
thank you everyone else for helping.

keith




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

Date: Tue, 08 May 2001 00:06:47 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <tfee4nd4he5b8c@corp.supernews.com>

Keith G (gasper@cis.ohio-state.edu) wrote:
: Sorry to have put everyone into a tizzy! I figured
: out the easiest way to do it was to avoid using
: Perl to do the redirection and to instead do this:

Well, you *are* using Perl, of course, given that you are excuting a print
in here...

: print "<script>location.replace(\"http://mypage.com\");</script>\n";

Note that you can avoid those nasty escapes on the quotes easily:

  print qq!<script>location.replace("http://mypage.com");</script>\n!;

But also note that this solution depends on the browser both understanding
Javascript and being allowed by the user to execute it.  Conversely, the
redirect solution will be supported by virtually any browser. 

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Mon, 07 May 2001 17:34:09 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <3AF73F01.8F6FCFDE@stomp.stomp.tokyo>

Keith G wrote:
 
> Sorry to have put everyone into a tizzy! I figured
> out the easiest way to do it was to avoid using
> Perl to do the redirection and to instead do this:

(snipped)

> This seems to work just fine. I'd love to respond
> to godzilla's knock about being a 'copy and paste
> baby' or needing to 'learn how to program,' but
> i've got more important things to concentrate on.
> thank you everyone else for helping.


I can tell you purchase the same brand of designer
shoes as Mueller, most likely the same size. If
the shoe fits, eh?

It is rare I say something like this, however, I am
in the mood with this being my 28th day and, being
under the influence of a full moon. Besides, I have
a reputation to maintain as a first class bitch.

You are full of mule manure, Bozo. You are just as
fake as is your initial fake troll article.

MUUUUHAHAHAHAHAAAAA!

Godzilla!


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

Date: Mon, 7 May 2001 17:04:08 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Simple Regex for URL to Filename
Message-Id: <6968-3AF71BD8-198@storefull-245.iap.bryant.webtv.net>

Thanks. I hope I picked the best solution for changing a URL into a
filename:-) A couple of the solutions posted to this thread didn't work.
I don't know of any URL's that don't have a slash in them, so I guess
the below is good code.

#!/usr/bin/perl -w
use LWP::Simple;
use CGI qw(:standard);
[ snip ]
$url =  param('url');
($file = $url) =~ s/^.*?\/([^\/]*?)$/$1/; 
getstore("$url", "$file") or print "Must RENAME file\n" and exit;

 .. no, I'm not trying to mirror a site.

Regards,
--Dennis



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

Date: Mon, 07 May 2001 22:42:24 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Simple Regex
Message-Id: <tfe96gbo48ij0a@corp.supernews.com>

BUCK NAKED1 <dennis100@webtv.net> wrote:
> How do I grab the part of a string from the last slash to EOL? for
> example: if I want to replace "http://my.com/images/banner.gif" with
> "banner.gif".

> I tried 
> $name =~ s/\/(.*?)\n/(.*?)\n/e and it failed.

example 1:

    my $string = 'http://my.com/images/banner.gif';
    $string = reverse $string;
    $string =~ s{^(.*?)/.*}{$1};
    $string = reverse $string;
    # single non-greedy match with substitution

example 2:

    my $string = 'http://my.com/images/banner.gif';
    $string = reverse $string;
    $string =~ m{^(.*?)/};
    $string = reverse $1;
    # single non-greedy match, substitution separate

example 3:

    my $string = 'http://my.com/images/banner.gif';
    $string =~ s{(?:.*?/)*(.*?)$}{$1};
    # non-greedy, multiple matches

example 4:

    my $string = 'http://my.com/images/banner.gif';
    $string = (split /\/+/, $string)[-1];
    # creates and ignores most of a list

example 5:

    my $string = 'http://my.com/images/banner.gif';
    $string =~ s{(?:.*/)(.*?)$}{$1};
    # greedy, singular match



Which of the above is best is left as an exercise. The
Benchmark module may come in handy.

Not only is TMTOWTDI, but there are more ways that I
have not listed.

Chris

--
For the pleasure of others, please adhere to the following
rules when visiting your park:
    No swimming.  No fishing.  No flying kites.  No frisbees.
    No audio equipment. Stay off grass.  No pets. No running.



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

Date: Mon, 07 May 2001 22:28:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sort String
Message-Id: <x7d79kdc97.fsf@home.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

  RLS> 97% of the uses of split /(___)/ can be replaced by a cleaner /(___)/g
  RLS> instead, in my observation.  I think the trouble is that we invented
  RLS> this split /(..)/ idiom before Perl5 came along, and now nobody is
  RLS> looking at the much cleaner m//g.

well, the main diff is that split is supposed to be used to match
separators and eat them while returning what is in between and m/()/
just matches substrings and returns any grabbed ones. they can do
similar things but they each have strengths and weaknesses. those should
be emphasized when teaching them. since there are no delims in that
string that the OP wants sorted, then m// makes more sense. if you had
'ab:cd' type strings then split makes more sense. maybe the docs should
contrast the two functions and show cases where one is better than the
other?

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 7 May 2001 22:50:38 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Sort String
Message-Id: <9d78ru$h1epl$2@fu-berlin.de>

"Jürgen Exner" <juex@deja.com> wrote:
> "root" <root@root.com> wrote in message
> news:3af6e549$1@addressworks2.umassd.edu...
>> Hi,
>>
>> Here's a little challenge.  I want to sort an alpha string grouped by two
>> characters. Example:
>> $original = "abracadeba"
>> after sort... (?)
>> $sorted = "abbacadera                            "
>> I want to do this with a minimum of code.

> Well, the only interesting part is obviously how to split the string into
> two-letter elements:
>     $sorted = join '', sort grep($_, split /(..)/, $original);

> Anyone wants to play golf on this?

yep =)
(my code is a little bit longer, but faster ;-)

00:40am tina@lux:tina 655> perl -e'$s="abracadeba";
sub tina {return sort unpack("A2"x((length $s)/2), $s)}
sub juergen {return join "", sort ($_, split /(..)/, $s)}
print tina();print juergen();
use Benchmark;
timethese($ARGV[0], {tina=>\&tina, juergen=>\&juergen});
' 50000
abbacaderaabbacaderaBenchmark: timing 50000 iterations of juergen, tina...
   juergen:  4 wallclock secs ( 3.45 usr +  0.00 sys =  3.45 CPU)
      tina:  1 wallclock secs ( 1.05 usr +  0.00 sys =  1.05 CPU)

regards,
tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Mon, 07 May 2001 23:09:09 GMT
From: "Dave" <djm@spamfree.mcoe.k12.ca.us>
Subject: Re: Sort String
Message-Id: <pWFJ6.9024$po.37024@typhoon.sonic.net>

This is Perl humor right?  Someone please tell me this wasnt for real ....


> (my code is a little bit longer, but faster ;-)
>
> 00:40am tina@lux:tina 655> perl -e'$s="abracadeba";
> sub tina {return sort unpack("A2"x((length $s)/2), $s)}
> sub juergen {return join "", sort ($_, split /(..)/, $s)}
> print tina();print juergen();
> use Benchmark;
> timethese($ARGV[0], {tina=>\&tina, juergen=>\&juergen});
> ' 50000
> abbacaderaabbacaderaBenchmark: timing 50000 iterations of juergen, tina...
>    juergen:  4 wallclock secs ( 3.45 usr +  0.00 sys =  3.45 CPU)
>       tina:  1 wallclock secs ( 1.05 usr +  0.00 sys =  1.05 CPU)
>
> regards,
> tina





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

Date: Mon, 07 May 2001 23:20:44 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Sort String
Message-Id: <tfebeclkjoaj35@corp.supernews.com>

Jürgen Exner (juex@deja.com) wrote:
:     $sorted = join '', sort grep($_, split /(..)/, $original);
: 
: Anyone wants to play golf on this?

  $sorted=join'',sort$original=~/../g;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Tue, 08 May 2001 00:45:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Sort String
Message-Id: <3AF741A6.D43BF0C0@acm.org>

Tina Mueller wrote:
> 
> yep =)
> (my code is a little bit longer, but faster ;-)

Except for the fact that his returns a scalar and yours returns a list.


> 00:40am tina@lux:tina 655> perl -e'$s="abracadeba";
> sub tina {return sort unpack("A2"x((length $s)/2), $s)}
> sub juergen {return join "", sort ($_, split /(..)/, $s)}
> print tina();print juergen();
> use Benchmark;
> timethese($ARGV[0], {tina=>\&tina, juergen=>\&juergen});
> ' 50000
> abbacaderaabbacaderaBenchmark: timing 50000 iterations of juergen, tina...
>    juergen:  4 wallclock secs ( 3.45 usr +  0.00 sys =  3.45 CPU)
>       tina:  1 wallclock secs ( 1.05 usr +  0.00 sys =  1.05 CPU)


John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 07 May 2001 22:47:06 GMT
From: Kathy Ramsey <ramseyk@home.com>
Subject: Re: Trying to fill in a Pager Web page.
Message-Id: <3AF725E9.26A1F8CE@home.com>

Got it Thanks works great!

Abigail wrote:

> Kathy Ramsey (ramseyk@home.com) wrote on MMDCCCV September MCMXCIII in
> <URL:news:3AF5B214.12231392@home.com>:
> <>  I am trying to feed a pager # and message to www.arch.com - a pager web
> <>  site.
> <>  where do I begin!
>
> By installing LWP.
>
> Abigail



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

Date: Mon, 07 May 2001 15:26:26 -0700
From: Taher <tfurnitu@cisco.com>
Subject: Unreasonable conversion . ERROR ORA-001460
Message-Id: <3AF72111.BCD5F6E6@cisco.com>

Hi everyone ,

I am trying to call a Oracle function which takes in a number of input
parameters .
I found out that if a parameter size was more than 32000(around 32K)
than it gave the following error
'DBD:Oracle:st execute failed:ORA-01460 unimplemented or unreasonable
conversion requested (DBD:exec error) at InsInventory.pl line 64, <>
chunk 9' .

Even though i am binding each parameter , the DBI documentation states
that the driver understands only string and number binding .
Or is there a 'long' binding which i am not aware of ?

Also setting of $dbh->{LongReadLen} = to a very large number is
basically meant for reading data ( ie a select ) .
Or does this effect insertion of long data too ?

Has anyone else faced problems inserting very large values through Perl
calling Oracle functions/stored procs ?

Following is a part of my code ...
my $sth = $dbh->prepare( "declare rt number ; begin  rt :=
sinsinventory(?,?,?
,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ; end;") ;
$sth->bind_param(1,$value,SQL_VARCHAR);
$sth->execute() ;

Thanks in advance for any help .... :-)

Taher.



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

Date: Mon, 07 May 2001 15:55:29 -0700
From: Taher <tfurnitu@cisco.com>
Subject: using DBI,unreasonable conversion error-ORA 01460
Message-Id: <3AF727E0.B4130DEA@cisco.com>

Hi everyone ,

I am trying to call a Oracle function which takes in a number of input
parameters .
I found out that if a parameter size was more than 32000(around 32K)
than it gave the following error
'DBD:Oracle:st execute failed:ORA-01460 unimplemented or unreasonable
conversion requested (DBD:exec error) at InsInventory.pl line 64, <>
chunk 9' .

Even though i am binding each parameter , the DBI documentation states
that the driver understands only string and number binding .
Or is there a 'long' binding which i am not aware of ?

Also setting of $dbh->{LongReadLen} = to a very large number is
basically meant for reading data ( ie a select ) .
Or does this effect insertion of long data too ?

Has anyone else faced problems inserting very large values through Perl
calling Oracle functions/stored procs ?

Following is a part of my code ...
my $sth = $dbh->prepare( "declare rt number ; begin  rt :=
sinsinventory(?,?,?
,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ; end;") ;
$sth->bind_param(1,$value,SQL_VARCHAR);
$sth->execute() ;

Thanks in advance for any help .... :-)

Taher.



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

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


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