[23430] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5647 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 11 14:06:19 2003

Date: Sat, 11 Oct 2003 11:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 11 Oct 2003     Volume: 10 Number: 5647

Today's topics:
        CGI.pm upload() <nospampleasethankyouta@somewhereinthebluenowhere.com>
    Re: CGI.pm upload() <flavell@ph.gla.ac.uk>
    Re: CGI.pm upload() (David Efflandt)
        Creating hyperlinks from text <dreamer@cox.net>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: End Record Charcter <invalid-email@rochester.rr.com>
    Re: How to parse e-mail messages? (Anno Siegel)
    Re: Old CGI scripts do not work under Mandrake 9.1 <me@privacy.net>
    Re: Old CGI scripts do not work under Mandrake 9.1 <ceri_hankey@wanadoo.fr>
    Re: Old CGI scripts do not work under Mandrake 9.1 <ceri_hankey@wanadoo.fr>
    Re: pattern matching <nospam@peng.nl>
        perl - cgi - how to displ a block of records with navig (shree)
    Re: perl - cgi - how to displ a block of records with n <mbudash@sonic.net>
        Reply every combination of letters (AGoodGuyGoneBad)
        sorting by multiple criterias (sub-sorting) (Tom Kirchner)
    Re: sorting by multiple criterias (sub-sorting) <cenxnfu@rpr.nevmban.rqh>
    Re: sorting by multiple criterias (sub-sorting) <grazz@pobox.com>
    Re: sorting by multiple criterias (sub-sorting) <mbudash@sonic.net>
    Re: strip text up to a keyword? (Tad McClellan)
    Re: Teach me how to fish, regexp (Tad McClellan)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 11 Oct 2003 10:52:37 +0100
From: "D Borland" <nospampleasethankyouta@somewhereinthebluenowhere.com>
Subject: CGI.pm upload()
Message-Id: <CpQhb.129$rE4.167087@newsfep1-win.server.ntli.net>

Hi Folks,

Can anyone here tell me if there is a safe alternative to CGI.pm's upload
function?

There main reason for needing this is that i am needing to upload multiple
files, (eg. image1, image2, image3, image4), but you can only pass the
upload function an actual param not a $scalar value, so this means i have to
specify each upload i will need and that means 4 times as much code, but
most of all is that when it fails to upload the files, it's impossible to
see what it failed on and why.

Hope i explained that OK :)

Thanks




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

Date: Sat, 11 Oct 2003 11:36:04 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI.pm upload()
Message-Id: <Pine.LNX.4.53.0310111131260.10229@ppepc56.ph.gla.ac.uk>

On Sat, 11 Oct 2003, D Borland wrote:

> Can anyone here tell me if there is a safe alternative to CGI.pm's upload
> function?

In what sense do you consider CGI.pm unsafe?

> There main reason for needing this is that i am needing to upload multiple
> files, (eg. image1, image2, image3, image4), but you can only pass the
> upload function an actual param not a $scalar value, so this means i have to
> specify each upload i will need and that means 4 times as much code,

I don't quite understand your point.  The current documentation says:

| You can have several file upload fields in the same form, and even
| give them the same name if you like (in the latter case param() will
| return a list of file names).

> but most of all is that when it fails to upload the files, it's
> impossible to see what it failed on and why.

That's awfully vague. If you have a Perl problem, let's see some
snippets of Perl here.

If your problem is more about how to organise your CGI script to do
what you want, rather than anything Perl-specific, you might be better
placed on comp.infosystems.www.authoring.cgi (check its automoderation
FAQ before posting).

good luck.


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

Date: Sat, 11 Oct 2003 16:01:54 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: CGI.pm upload()
Message-Id: <slrnbogabi.iuk.efflandt@typhoon.xnet.com>

On Sat, 11 Oct 2003, D Borland <afraidofspam@somewhere.invalid> wrote:
> Can anyone here tell me if there is a safe alternative to CGI.pm's upload
> function?
> 
> There main reason for needing this is that i am needing to upload multiple
> files, (eg. image1, image2, image3, image4), but you can only pass the
> upload function an actual param not a $scalar value, so this means i have to
> specify each upload i will need and that means 4 times as much code, but
> most of all is that when it fails to upload the files, it's impossible to
> see what it failed on and why.

The first thing a newbie needs to learn is how to include error checking 
in your code, so your script will be nice enough to tell you what is 
wrong.  But that assumes that you tested it in a shell first to eliminate 
precompile errors (like missing ';' or mismatched quotes or brackets).

You could download multiple files (like consecutively numbered names) with 
a loop (function method example).

# assuming any 1 to 5 files w/field names image1..image5
for $i (1..5) {
    my $upload;
    if ($upload = param('image'.$i)) {
        # Pull filename from end of any browser supplied path
        if ($upload =~ m|[/\\:]|) {
            $upload =~ m|[/\\:]+([^/\\:]+)$|;
            $upload = $1;
        }
        # add filename tests to assure compatible/non-conflicting name 
        # like substitute underlines for spaces, etc.
        # do something useful with $upload
    }
}

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/


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

Date: Sat, 11 Oct 2003 09:01:39 -0700
From: Fred <dreamer@cox.net>
Subject: Creating hyperlinks from text
Message-Id: <3F882963.AF09DD02@cox.net>

Hello there,

I copy and paste snippets from newsletters (and other messages) to
large textfiles. I use Perl to add HTML labels for formatting, and I
use the following code to convert URL's to hyperlinks:

local $/;

	while (<>){

		s/ *?(http:.+?) *?[^<]\n/<p><a href="$1">\n$1<\/a><br>\n/igs ;
		
		print $_;
    	}

I have converted textfiles with about 300 URL's and so far all
hyperlinks created worked fine in Mozilla. 

Question: How could I do the conversion to hyperlinks with a module?

---
Fred


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

Date: 11 Oct 2003 11:13:23 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1065870682@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            XEmacs port is bundled in XEmacs setup.exe available from
            XEmacs site.

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
        <ilya@math.ohio-state.edu>    Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr@ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: Sat, 11 Oct 2003 04:05:10 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: End Record Charcter
Message-Id: <3F877F1E.2060506@rochester.rr.com>

Bruce.Dobson wrote:

> I am trying to learn some Perl and doing a tutorial which has the following
> code.
> %grades = ();
> print "Enter student names (press <cntrl>+D when done:";
> @names = <STDIN>;
> chomp @names;
> print "\n\n";
> print "Enter corresponding grades (press <cntrl>+D when done):";
> @scores = <STDIN>;
> @grades{@names} = @scores;
> 
> It refers to <cntrl>+D as the "end record character", but this does not seem
> to work for me when I run the programme.
> I installed ActivePerl-5.8.0.806-MSWin32-x86.msi on Windows XP.
> Can anybody tell me why I cannot get <Cntrl>+D to work or what I use for the
> end record character instead of  <Cntrl>+D.
> 

Control-D has nothing to do with Perl per se, but is an operating system 
feature.  Generally control-D may be used to give an end-of-file 
indication on console input to an application on a Unix system.  On 
Windoze, it is more or less a control-Z.  Your mileage might vary 
depending upon your version of Windoze -- some versions have a bug which 
hides the next line of output from your program following a control-Z, 
which can be most highly confusing.  This is a Windoze bug, since other 
programs besides Perl do it too.  A workaround is to simply output an 
extra blank line before printing anything else after a control-Z. 
Better yet (paricularly in the case with data like you've got) would be 
to key the data into a file using an editor, and then read that file 
with Perl.  That way one typo doesn't ruin a long series of data input, 
and you get to run various versions of your program, or even other 
programs, on the data without having to type it all in again.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: 11 Oct 2003 09:42:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to parse e-mail messages?
Message-Id: <bm8j9k$c68$1@mamenchi.zrz.TU-Berlin.DE>

Experienced but Undocumented <e02@removethis.toao.net> wrote in comp.lang.perl.misc:
> Is there a PERL module that will parse raw e-mail messages?  I'm using

Lots.  When you search CPAN for "Mail" and "Email", you'll find them.

> Net::POP3 to download them off a server, but I would like to strip any HTML
> or Rich Text and just leave plain text.

A mail module is unlikely to understand HTML or RTF.  While you're at it,
search for those keywords too.

Anno


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

Date: Sat, 11 Oct 2003 23:09:19 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Old CGI scripts do not work under Mandrake 9.1
Message-Id: <bm8ktv$k4v22$1@ID-172104.news.uni-berlin.de>


"Ceri Hankey" <cerih@exportlink.ch> wrote in message
news:3F872EDF.9020302@exportlink.ch...
> Hi,
>
> I have a few CGI scripts that worked fine under mandrake 8.1 and apache
> 1.3.?, but having UPGRADED (ie not a new installation) to Mandrake 9.1
> and Apache 2.0, I keep on getting a 'file not found' error whwn I run
> the scripts - in var/log/httpd/error22.log.
>
> The CGI scripts appear to work fine when called via 'perl -d
> scriptname', but fail when called via a Web page.
>
> What has changed in Mandrake 9.1 vs 8.1? Is it Perl or Apache? and where?

It's Apache and hence off-topic for this group.




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

Date: Sat, 11 Oct 2003 12:10:05 +0200
From: "Ceri Hankey" <ceri_hankey@wanadoo.fr>
Subject: Re: Old CGI scripts do not work under Mandrake 9.1
Message-Id: <bm8l0a$h53$1@news-reader3.wanadoo.fr>

Tks for reply...
Yeah, it sure looks like an http config problem. Sure would like to know
which file cannot be found - I have tried everything to try to trace this.
Is there any way to get more data in the log files - I have set the LogLevel
to debug, but still do net get not much info on the 'missing' file!


"Sisyphus" <kalinaubears@iinet.net.au> a écrit dans le message de
news:3f877166$0$23589$5a62ac22@freenews.iinet.net.au...
> Ceri Hankey wrote:
> > Hi,
> >
> > I have a few CGI scripts that worked fine under mandrake 8.1 and apache
> > 1.3.?, but having UPGRADED (ie not a new installation) to Mandrake 9.1
> > and Apache 2.0, I keep on getting a 'file not found' error whwn I run
> > the scripts - in var/log/httpd/error22.log.
> >
> > The CGI scripts appear to work fine when called via 'perl -d
> > scriptname', but fail when called via a Web page.
> >
> > What has changed in Mandrake 9.1 vs 8.1? Is it Perl or Apache? and
where?
> >
>
> Don't kmow but it sounds to me like an Apache configuration issue.
> You've got a new Apache in the upgrade - and I would think that the
> configuration file (httpd.conf, iirc) has been overwritten, and needs
> editing. I would start by checking that.
>
> Which "file" is "not found" ? I assume it's the perl script.


>
> Hth.
>
> Cheers,
> Rob
>
>
> -- 
> To reply by email u have to take out the u in kalinaubears.
>




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

Date: Sat, 11 Oct 2003 15:26:12 +0200
From: "Ceri Hankey" <ceri_hankey@wanadoo.fr>
Subject: Re: Old CGI scripts do not work under Mandrake 9.1
Message-Id: <bm90ft$42d$1@news-reader5.wanadoo.fr>

More question re Perl

How to get rid of the following error (in /var/log/httpd/error22_log) when I
try to run a cgi script...

modperl_callback_run_handlers: no PerlChildInitHandler handlers configured
()

What is the correct call please?




"Tintin" <me@privacy.net> a écrit dans le message de
news:bm8ktv$k4v22$1@ID-172104.news.uni-berlin.de...
>
> "Ceri Hankey" <cerih@exportlink.ch> wrote in message
> news:3F872EDF.9020302@exportlink.ch...
> > Hi,
> >
> > I have a few CGI scripts that worked fine under mandrake 8.1 and apache
> > 1.3.?, but having UPGRADED (ie not a new installation) to Mandrake 9.1
> > and Apache 2.0, I keep on getting a 'file not found' error whwn I run
> > the scripts - in var/log/httpd/error22.log.
> >
> > The CGI scripts appear to work fine when called via 'perl -d
> > scriptname', but fail when called via a Web page.
> >
> > What has changed in Mandrake 9.1 vs 8.1? Is it Perl or Apache? and
where?
>
> It's Apache and hence off-topic for this group.
>
>




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

Date: Sat, 11 Oct 2003 10:14:45 +0100
From: "Lex" <nospam@peng.nl>
Subject: Re: pattern matching
Message-Id: <bXPhb.3064$1V5.49268@news-reader.eresmas.com>


"Bob Walton" <invalid-email@rochester.rr.com> wrote in message
news:3F84ABBC.1000607@rochester.rr.com...

>  Trust me, it will
> save you gobs of time to take the time to install Perl on your local
> machine.
>

Thanks Bob,

You've convinced me. I'll go and try it out...

Lex




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

Date: 11 Oct 2003 07:52:42 -0700
From: srigowrisn@hotmail.com (shree)
Subject: perl - cgi - how to displ a block of records with navigational hyperlinks
Message-Id: <49b5740e.0310110652.6223ce71@posting.google.com>

Hello,

First off, pls forgive me if this appears repeated..I had posted a
similar ques a while ago but could not find fix back then, but found a
workaround for it at the time.

Objective:
How to get a block of records at a time from a flat file database and
display it as an html table, with navigational hyperlinks to index
forward to the next block of records, or index backward to a previous
block of records.

My workaround previously was to import flatfile into a MySQL database
and modify SQL stmts in my perl-cgi scripts. I don't have the luxury
of this option currently..hence, I'm stuck and would appreciate
hearing suggestions.

I have pasted sample data, code, output this code generates and output
I would like to see..hence, request to help identify and fix the code.

Data File name: TestData
----Sample Data------
RecordID|Last Name|First Name|Date Entered|Details
1|Smith|John|2003/10/01|ID1 Details
2|Smith|Joe|2003/10/02|ID2 Details
3|Smith|Mary|2003/10/03|ID3 Details
4|Smith|John4|2003/10/04|ID4 Details
5|Smith|John5|2003/10/05|ID5 Details
6|Smith|John6|2003/10/06|ID6 Details
7|Smith|John7|2003/10/07|ID7 Details
8|Smith|John8|2003/10/08|ID8 Details
9|Smith|John9|2003/10/09|ID9 Details
10|Smith|John10|2003/10/10|ID10 Details

Code name: Disp2Records.cgi
----Code------

#!/usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;

my $items = 2; #Disp 2 records at a time..increase this later
my $start_item = param('start') || 0 ;

my $me = script_name();

my (@data_array) = ();
my ($next_items, $prev_items) = "";

print header;
print start_html('TestDatabase - Records Display');

my $File_Data = "TestData";

if (open(FILE, $File_Data ) or die "Cannot open $File_Data $!")
  {
     while(<FILE>)
       {
         chomp;
         my @stuff = split /\|/,$_;
         push @data_array,\@stuff;
       }
     print "<TABLE>\n";
     foreach (@data_array[$start_item ... ($start_item + $items - 1)])
        {
          print Tr(td(@{$_})),"\n";
        	
        }
     print "</TABLE>\n";
     $prev_items = $start_item - $items;
     $prev_items = 0 if ($prev_items < 0 );
     $next_items = $start_item + $items;
     $next_items = 0 if ($next_items > $#data_array);

     print "<TABLE WIDTH=100%>\n";
     print "<TR WIDTH=100%>\n";
     print "<TD WIDTH=50% ALIGN=left>\n";
     if ( $start_item > 0 )
       {
         print "<A HREF=$me?start=$prev_items>Previous Page</A>\n";
       }
     print "</TD>\n";
     print "<TD WIDTH=50% ALIGN=right>\n";
     if ( $next_items > 0 )
       {
         print "<A HREF=$me?start=$next_items>Next Page</A>\n";
       }
     print "</TD>\n";
     print "</TR>\n</TABLE>\n";
  }
else
  {
    print h1('Couldnt open file');
  }

print end_html; 

------Output the code generates when script is -------
Please note: I have pasted content between <body> </body> tags only as
thats the only part thats relevant for the discussion.

<body>
<TABLE>
<tr><td>RecordID Last Name First Name Date Entered Details</td></tr>
<tr><td>1 Smith John 2003/10/01 ID1 Details</td></tr>
</TABLE>
<TABLE WIDTH=100%>
<TR WIDTH=100%>
<TD WIDTH=50% ALIGN=left>
</TD>
<TD WIDTH=50% ALIGN=right>
<A HREF=/cgi-bin/Disp2Records.cgi?start=2>Next Page</A>
</TD>
</TR>
</TABLE>
</body>

Note In the 1st TABLE block, between <tr> to </tr> it stuffs entire
line (one record) into one <td> </td> tag. Instead I would like it to
be

<TABLE>
<tr><td>RecordID</td><td>Last Name</td><td>First Name</td><td>Date
Entered Details</td></tr>
<tr><td>1</td><td>Smith</td><td>John</td><td>2003/10/01</td><td>ID1
Details</td></tr>
</TABLE>

Later..it would be nice to have hyperlinks to allow user to jump to
end or anywhere in between..similar to google search. Suppose there
are 100 records and we're displaying 10 records at a time. In the
inital results, it will display records 1 - 10, and will have
hyperlinks for 11-20, 21-30 and so on..till 91 - 100. Hence, display 9
hyperlinks.

I appreciate any help and guidance you can offer.

Thank you,
Shree


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

Date: Sat, 11 Oct 2003 15:57:46 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: perl - cgi - how to displ a block of records with navigational hyperlinks
Message-Id: <mbudash-A6FD4F.08574611102003@typhoon.sonic.net>

In article <49b5740e.0310110652.6223ce71@posting.google.com>,
 srigowrisn@hotmail.com (shree) wrote:

> Hello,
> 
> First off, pls forgive me if this appears repeated..I had posted a
> similar ques a while ago but could not find fix back then, but found a
> workaround for it at the time.
> 
> Objective:
> How to get a block of records at a time from a flat file database and
> display it as an html table, with navigational hyperlinks to index
> forward to the next block of records, or index backward to a previous
> block of records.
> 
> My workaround previously was to import flatfile into a MySQL database
> and modify SQL stmts in my perl-cgi scripts. I don't have the luxury
> of this option currently..hence, I'm stuck and would appreciate
> hearing suggestions.
> 
> I have pasted sample data, code, output this code generates and output
> I would like to see..hence, request to help identify and fix the code.
> 
> Data File name: TestData
> ----Sample Data------
> RecordID|Last Name|First Name|Date Entered|Details
> 1|Smith|John|2003/10/01|ID1 Details
> 2|Smith|Joe|2003/10/02|ID2 Details
> 3|Smith|Mary|2003/10/03|ID3 Details
> 4|Smith|John4|2003/10/04|ID4 Details
> 5|Smith|John5|2003/10/05|ID5 Details
> 6|Smith|John6|2003/10/06|ID6 Details
> 7|Smith|John7|2003/10/07|ID7 Details
> 8|Smith|John8|2003/10/08|ID8 Details
> 9|Smith|John9|2003/10/09|ID9 Details
> 10|Smith|John10|2003/10/10|ID10 Details
> 
> Code name: Disp2Records.cgi
> ----Code------
> 
> #!/usr/bin/perl -w

good so far

> 
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> use strict;

excellent

> 
> my $items = 2; #Disp 2 records at a time..increase this later
> my $start_item = param('start') || 0 ;
> 
> my $me = script_name();
> 
> my (@data_array) = ();
> my ($next_items, $prev_items) = "";

s/b:

my (@data_array, $next_items, $prev_items);

> 
> print header;
> print start_html('TestDatabase - Records Display');
> 
> my $File_Data = "TestData";
> 
> if (open(FILE, $File_Data ) or die "Cannot open $File_Data $!")

good error handling

>   {

insert this here:

     # start the results table
     print "\n<TABLE>\n";

     # retrieve and show the column headings
     my $header = <FILE>;
     chomp $header;
     my @row = split /\|/,$header;       
     print Tr(td(\@row)); # note: using reference generates separate td's

>      while(<FILE>)
>        {
>          chomp;
>          my @stuff = split /\|/,$_;
>          push @data_array,\@stuff;
>        }

next line no longer needed:

>      print "<TABLE>\n";
>      foreach (@data_array[$start_item ... ($start_item + $items - 1)])
>         {
>           print Tr(td(@{$_})),"\n";
>         }
>      print "</TABLE>\n";

[snip rest of code - looks ok and works fine]

[snip output of original code]

> Note In the 1st TABLE block, between <tr> to </tr> it stuffs entire
> line (one record) into one <td> </td> tag. Instead I would like it to
> be
> 
> <TABLE>
> <tr><td>RecordID</td><td>Last Name</td><td>First Name</td><td>Date
> Entered Details</td></tr>
> <tr><td>1</td><td>Smith</td><td>John</td><td>2003/10/01</td><td>ID1
> Details</td></tr>
> </TABLE>

the code will do as you ask now

> 
> Later..it would be nice to have hyperlinks to allow user to jump to
> end or anywhere in between..similar to google search. Suppose there
> are 100 records and we're displaying 10 records at a time. In the
> inital results, it will display records 1 - 10, and will have
> hyperlinks for 11-20, 21-30 and so on..till 91 - 100. Hence, display 9
> hyperlinks.

there are cpan modules that will assist you in this. no need to write it 
yourself. for that matter, the same modules could've helped you with the 
'previous' and 'next ' links as well...

-- 
Michael Budash


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

Date: 11 Oct 2003 06:14:16 GMT
From: agoodguygonebad@aol.com (AGoodGuyGoneBad)
Subject: Reply every combination of letters
Message-Id: <20031011021416.15443.00000854@mb-m28.aol.com>

>Hi Folks,
>
>I need to write two programs for a school assignment. One is an
>"efficient" anagram program that will find all anagrams for a given
>word by sorting all given letters of the supplied word and dictionary
>which will then find all of the matching words.
>
>The next version of the program (the "inefficient" example) is
>supposed to try every combination of letters and find anagrams by pure
>brute force by trying every combination of letters up to
>len($suppliedWord) in length.
>
>I'm not looking for someone to do this for me, I'm looking for advice
>on how do I go about trying every possible combination of letters. It
>sounds pretty easy on the surface but as I think about it more it
>seems to get messier and messier.
>
>Does soemone know of a "clean" method I can use to iterate through
>every possible combination of letters?
>
>
>Thanks,
>Roger
>

Q1
If you are given a dictionary, look through it for words that contain the
letters given.
That is much easier to do, than creating words and seeing it they exist.

If you're not given a dictionary, steal one. I have a simple anagram program I
wrote for a friend that plays Wordox, and was able for find The Wordox
Dictionary with the words group into files of 2 letter, 3 letter, 4 letter,
etc.

Q2
It's very easy to create every combinations, all permutations or permuted
combinations.
By permuted combinations, I mean combinations that are sorted permutations,
usually written as 26_C_5

a demo

# Program to Calculate Permutations
# if you have the letters 'emst'
# you won't get things like meet,seem
# if you do want them, use 'emst' $n=4;$r=4;$a=1;


#$letters = " abcdefghijklmnop";
$letters = " emst";
# use a space for first

$n = 4;  # number of letters
$r = 4;  # length of word - program only works for <=5
         # unless you add more loops and OR's
$a = 0;  # 0 for Permutations, 1 for all possible

if ($a==1) {
   $total = $n**$r;
   print "there are $total ways to make $n^$r\n";
} else {
   $p=1; for ($w=1; $w < $r; $w++) {$p = ($n-$w)*$p;}
   $p=$n*$p;
   print "there are $p Permutations for $n";
   print "_P_$r\n";
}

for ($k=1; $k<=$n; $k++) {$v[$k] = substr($letters,$k,1);}

for ($m1=1; $m1<=$n; $m1++) {
for ($m2=1; $m2<=$n; $m2++) {

if ($r==2) {
 if ($a==0) {
   if ($m1==$m2) {next;} 
 }
   $words.= $v[$m1].$v[$m2]." ";
}

for ($m3=1; $m3<=$n; $m3++) {
if ($r==3) {
 if ($a==0) {
  if ($m1==$m2 || $m2==$m3 || $m1==$m3) {next;}
 }
    $words.= $v[$m1].$v[$m2].$v[$m3]." ";
}

for ($m4=1; $m4<=$n; $m4++) {
if ($r==4) {
 if ($a==0) {
  if ($m1==$m2 || $m1==$m3 || $m1==$m4 || $m2==$m3 || $m2==$m4 || $m3==$m4)
{next;}
}
    $words.= $v[$m1].$v[$m2].$v[$m3].$v[$m4]." ";
}

for ($m5=1; $m5<=$n; $m5++) {
if ($r==5) {
 if ($a==0) {
  if ($m1==$m2 || $m1==$m3 || $m1==$m4 || $m1==$m5 || $m2==$m3 || $m2==$m4 ||
$m2==$m5 || $m3==$m4 || $m3==$m5 || $m4==$m5) {next;}
 }
    $words.= $v[$m1].$v[$m2].$v[$m3].$v[$m4].$v[$m5]." ";
}
}}}}}
print $words;

Steve
HTH


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

Date: 11 Oct 2003 09:28:51 -0700
From: tokirc@gmx.net (Tom Kirchner)
Subject: sorting by multiple criterias (sub-sorting)
Message-Id: <2d26cccb.0310110828.210b0ea0@posting.google.com>

hello!

Im currently writing on a part of a program where there is an
array of hash-refs holding data. and I want to sort these
array-elements (the hash-refs) by a first criteria and then
another one. E.g. If each hash would be something like:

@array = (
  { 'name' => 'dan', 'age' => '12', 'shoesize' => '34' },
  { 'name' => 'tom', 'age' => '19', 'shoesize' => '56' },
  { 'name' => 'tom', 'age' => '23', 'shoesize' => '43' },
  { 'name' => 'frank', 'age' => '42', 'shoesize' => '24' },
  # ...
);

what I want is: sorting first by 'name' and then, when there
are multiple records with the same name, sorting this (sub)group
by their 'age' and if there are records with the same
name and same age, sorting these by their shoesize.
This is just an example and the real thing is much more
complex, but I need a general idea of how this could be done.

thanks
tom


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

Date: Sat, 11 Oct 2003 09:51:18 -0700
From: Cognition Peon <cenxnfu@rpr.nevmban.rqh>
Subject: Re: sorting by multiple criterias (sub-sorting)
Message-Id: <Pine.GSO.4.50.0310110938590.2212-100000@shelltoe.ece.arizona.edu>

9:28am, IP packets from Tom Kirchner delivered:

> hello!
>
> Im currently writing on a part of a program where there is an
> array of hash-refs holding data. and I want to sort these
> array-elements (the hash-refs) by a first criteria and then
> another one. E.g. If each hash would be something like:
>
> @array = (
>   { 'name' => 'dan', 'age' => '12', 'shoesize' => '34' },
>   { 'name' => 'tom', 'age' => '19', 'shoesize' => '56' },
>   { 'name' => 'tom', 'age' => '23', 'shoesize' => '43' },
>   { 'name' => 'frank', 'age' => '42', 'shoesize' => '24' },
>   # ...
> );

sub sort_func {
        $a->{name} cmp $b->{name} ||
        $a->{age} <=> $b->{age} ||
        $a->{shoesize} <=> $b->{shoesize}
}

@sorted_array = sort sort_func (@array);


>
> what I want is: sorting first by 'name' and then, when there
> are multiple records with the same name, sorting this (sub)group
> by their 'age' and if there are records with the same
> name and same age, sorting these by their shoesize.
> This is just an example and the real thing is much more
> complex, but I need a general idea of how this could be done.
>
> thanks
> tom
>

-- 
echo cenxnfu@rpr.nevmban.rqh | perl -pe 'y/A-Za-z/N-ZA-Mn-za-m/'
T h i s   t a g l i n e   h a s   b e e n   u n z i p p e d .


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

Date: Sat, 11 Oct 2003 17:13:52 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: sorting by multiple criterias (sub-sorting)
Message-Id: <kTWhb.649$0I6.171@nwrdny03.gnilink.net>

Tom Kirchner <tokirc@gmx.net> wrote:
> Im currently writing on a part of a program where there is an
> array of hash-refs holding data. and I want to sort these
> array-elements (the hash-refs) by a first criteria and then
> another one. 

There are two FAQs dealing with this topic:

  % perldoc -q sort

> E.g. If each hash would be something like:
> 
> @array = (
>   { 'name' => 'dan', 'age' => '12', 'shoesize' => '34' },

Just a style nit:

    { name => 'dan', age => 12, shoesize => 34 },

>   { 'name' => 'tom', 'age' => '19', 'shoesize' => '56' },
>   { 'name' => 'tom', 'age' => '23', 'shoesize' => '43' },
>   { 'name' => 'frank', 'age' => '42', 'shoesize' => '24' },
>   # ...
> );
> 
> what I want is: sorting first by 'name' and then, when there
> are multiple records with the same name, sorting this (sub)group
> by their 'age' and if there are records with the same
> name and same age, sorting these by their shoesize.

Quoting from "How do I sort an array by (anything)?"

    If you need to sort on several fields, the following paradigm
    is useful.

        @sorted = sort { field1($a) <=> field1($b) ||
                         field2($a) cmp field2($b) ||
                         field3($a) cmp field3($b)
                        }     @data;

This works because when two elements of the input list are
equal, the <=> and cmp operators will return zero (and the
sub will fall through to the next comparison).

To adapt it to your example, just substitute hash lookups for
the subroutine call.

    @sorted = sort { $a->{name} cmp $b->{name} ||
                     $a->{age}  <=> $b->{age}  ...

-- 
Steve



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

Date: Sat, 11 Oct 2003 17:16:18 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: sorting by multiple criterias (sub-sorting)
Message-Id: <mbudash-8458C4.10161811102003@typhoon.sonic.net>

In article 
<Pine.GSO.4.50.0310110938590.2212-100000@shelltoe.ece.arizona.edu>,
 Cognition Peon <cenxnfu@rpr.nevmban.rqh> wrote:

> 9:28am, IP packets from Tom Kirchner delivered:
> 
> > hello!
> >
> > Im currently writing on a part of a program where there is an
> > array of hash-refs holding data. and I want to sort these
> > array-elements (the hash-refs) by a first criteria and then
> > another one. E.g. If each hash would be something like:
> >
> > @array = (
> >   { 'name' => 'dan', 'age' => '12', 'shoesize' => '34' },
> >   { 'name' => 'tom', 'age' => '19', 'shoesize' => '56' },
> >   { 'name' => 'tom', 'age' => '23', 'shoesize' => '43' },
> >   { 'name' => 'frank', 'age' => '42', 'shoesize' => '24' },
> >   # ...
> > );
> >
> > what I want is: sorting first by 'name' and then, when there
> > are multiple records with the same name, sorting this (sub)group
> > by their 'age' and if there are records with the same
> > name and same age, sorting these by their shoesize.
> > This is just an example and the real thing is much more
> > complex, but I need a general idea of how this could be done.
> 
> sub sort_func {
>         $a->{name} cmp $b->{name} ||
>         $a->{age} <=> $b->{age} ||
>         $a->{shoesize} <=> $b->{shoesize}
> }
> 
> @sorted_array = sort sort_func (@array);

of course, the o.p. does not _have_ to use a subroutine:

@sorted_array = sort {
        $a->{name} cmp $b->{name} ||
        $a->{age} <=> $b->{age} ||
        $a->{shoesize} <=> $b->{shoesize}
} @array;

-- 
Michael Budash


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

Date: Sat, 11 Oct 2003 00:04:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: strip text up to a keyword?
Message-Id: <slrnbof3qf.6nu.tadmc@magna.augustmail.com>

kw <anon002001@yahoo.com> wrote:
    ^^^^
    ^^^^ consider using some other name.


>> $webpage =~ s/^.*$string//s; 
> 
>> $_[0] =~ s/.*$keyword//s;    
> 
> Do these work through multiple linefeeds 


What happened when you tried it?


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


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

Date: Fri, 10 Oct 2003 23:58:05 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Teach me how to fish, regexp
Message-Id: <slrnbof3et.6nu.tadmc@magna.augustmail.com>

Henry <henryn@zzzspacebbs.com> wrote:
> in article slrnboehdb.6fl.tadmc@magna.augustmail.com, Tad McClellan at
> tadmc@augustmail.com wrote on 10/10/03 4:50 PM:


>> I prefer to use vi and grep to read the raw *.pod files.
> 
> I'm perfectly willing to use grep, but vi is pushing it.


vi is "meta" there.

Substitute "my favorite editor" where I said "vi".


> either brilliant or
> appallingly chaotic, I'm not sure yet.


We get that a lot here.   :-)

I remember when I first learned Perl too...


Just in case you don't have enough to read yet (heh), here's Larry
talking about how Perl is more like natural language that most
"conventional" programming languages:

   http://www.wall.org/~larry/natural.html


Perl is a bit of a shift in thinking if you are used to other 
programming languages.


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


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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