[17186] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4598 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 12 18:05:52 2000

Date: Thu, 12 Oct 2000 15:05:23 -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: <971388322-v9-i4598@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 12 Oct 2000     Volume: 9 Number: 4598

Today's topics:
        $] <rcook@pcug.org.au>
        Asyncronous Queue <mpav@algx.net>
    Re: Calculating in Perl. (Vipul Ved Prakash)
    Re: Calling Perl scripts inside HTML file within a Wind <aycwong2@yahoo.com>
    Re: cgi with perl on Apache-1.3.12-Linux-6.2 - beginner <newsposter@cthulhu.demon.nl>
    Re: cgi with perl on Apache-1.3.12-Linux-6.2 - beginner abevec@my-deja.com
    Re: Changing name of file in header? nobull@mail.com
    Re: Concurrent access to data nobull@mail.com
        convert tab to comma delimited <smeast@kcc.com>
    Re: convert tab to comma delimited (Flint Slacker)
    Re: convert tab to comma delimited (Bernard El-Hagin)
    Re: convert tab to comma delimited (Brett W. McCoy)
    Re: convert tab to comma delimited <uri@sysarch.com>
    Re: convert tab to comma delimited (Brett W. McCoy)
    Re: convert tab to comma delimited <jeff@vpservices.com>
    Re: convert tab to comma delimited <jeff@vpservices.com>
    Re: Cutesy Arrows - Just say nope! (David Wall)
        Erroneous Forward Slash in HTML Code by CGI.pm micah26@my-deja.com
    Re: Erroneous Forward Slash in HTML Code by CGI.pm <jeff@vpservices.com>
        hash value to XML::Parser handler <nlymbo@mindspring.com>
    Re: Help with newbie question <michael.segulja@sgi-lsi.com>
    Re: Help with newbie question (Chris Fedde)
    Re: hoe to alter @INC? <mauldin@netstorm.net>
    Re: How can I add 5 hours to the time my server reports <lincmad001@telecom-digest.zzn.com>
    Re: interpreting hidden backslash constructs <lr@hpl.hp.com>
    Re: ip under win9x/2k from the commandline? <lr@hpl.hp.com>
    Re: ip under win9x/2k from the commandline? (Steven M. O'Neill)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 13 Oct 2000 09:08:53 +1000
From: Owen Cook <rcook@pcug.org.au>
Subject: $]
Message-Id: <tcgcuskanfh5tlphj0v2obp043binqv9ge@4ax.com>

The program below gives the results shown. The definition I have of $]
reads "...the version string that identifies the Perl version.."

I can't reconcile the two numbers produced, other that there is a "5"
and a "6' in each

Presumeably there is some difference in interpretation between "version
sting" and the "Perl version"


Owen

 


-------------------------------------------------
#!/usr/bin/perl -w

print "$] \n";

exec ("perl -v");

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

[root@localhost cgi-bin]# perl t1.cgi
5.006

This is perl, v5.6.0 built for i686-linux
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2000, Larry Wall   

<snip>        



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

Date: Thu, 12 Oct 2000 15:01:41 -0500
From: Matt Pavlovich <mpav@algx.net>
Subject: Asyncronous Queue
Message-Id: <39E618A5.57762350@algx.net>

I am having problems implementing an async queue in perl and could use
some ideas.

The project:

Manage a series of jobs that require the use of limited resources.

A job can have mulitple processes (ie. run the same job 100 times).
Each process utilizes one of the limited resources.  My goal is to be
able to queue up jobs and wait until resources become available
(previous processes finish, thus freeing used resources), and then run
the queued jobs.

I would also like to be able to add jobs while the queue is running.

Originally, I was going to use a pair of daemons.  The first accepting
multiple connections, and checking configuration data for accuracy, then
sending the data to the queue daemon (accepts only one connection) to
insert the job into the queue.

This design isn't working as I keep stumbling to find a way to keep the
queue processing while accepting new jobs at the same time.

The resource managing works fine.  It can support adding of jobs on the
fly (using global variables) and works great.  I am stuck with handling
incoming connections, while the queue is still running.

I am fairly new to perl, so I may not be utilizing packages, or
functions that are already available.  Any guidance would be
appreciated.

Regards,
Matt Pavlovich
mpav@algx.net
Allegiance Telecom, Inc.



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

Date: 12 Oct 2000 22:02:20 GMT
From: vipul@shell2.ba.best.com (Vipul Ved Prakash)
Subject: Re: Calculating in Perl.
Message-Id: <slrn8ucd7c.ngu.vipul@shell2.ba.best.com>

Paul Dortman wrote:
>Hello!
>
>I'm writing program in Perl, that must perform calculation with certain
>accuracy. I'll try to explain what I mean: I need to have all
>calculations (addition, subtraction,  multiplication and division) only
>with two or three digits after decimal point. Standard Perl calculation is
>not appropriate, they have not high accuracy and it is not convenient to
>round result each time.
>
>Does anybody know is there any available module for these purposes?
>
>Can anybody give me advice?

use Math::Pari qw(setprecision pari_print);
setprecision( 3 );
print pari_print ( 2/3.0 );

# prints 0.666

best,
vipul.

--

Vipul Ved Prakash, http://www.vipul.net/
PGP Fingerprint d5f78d9fc694a45a00ae086062498922




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

Date: Thu, 12 Oct 2000 21:10:05 -0000
From: <aycwong2@yahoo.com>
Subject: Re: Calling Perl scripts inside HTML file within a Windows environment
Message-Id: <suca5d1en47e82@corp.supernews.com>

ok. So may I ask which group should I be posting to? I'm not a frequent 
newsgroup user. Thanx. 


David Steuber wrote:
> 
> This is a webserver question.
> 
> -- 
> David Steuber | Perl apprentice, Apache/mod_perl user,
> NRA Member    | and general Internet web wannabe.
> ICQ# 91465842
> ***         http://www.david-steuber.com/          ***


--
Posted via CNET Help.com
http://www.help.com/


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

Date: 12 Oct 2000 18:05:35 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: cgi with perl on Apache-1.3.12-Linux-6.2 - beginner
Message-Id: <8s4uhf$jv6$1@internal-news.uu.net>

abevec@my-deja.com wrote:

> I created a cgi Perl script in my cgi-bin directory that is suppose to
> get executed on an "get" html command.  But the Appache server comes
> back with an error.  I'm the server administrator.  All the
> files/directories are mode 755 protected.  Any ideas how to correct this
> problem.

http://www.cpan.org/doc/FAQs/cgi/idiots-guide.html

> More information about this error may be available in the server error
> log."

  And? Did you look in the server error log?

Erik



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

Date: Thu, 12 Oct 2000 18:31:47 GMT
From: abevec@my-deja.com
Subject: Re: cgi with perl on Apache-1.3.12-Linux-6.2 - beginner
Message-Id: <8s502k$sr3$1@nnrp1.deja.com>

In article <8s4tmr$qke$1@nnrp1.deja.com>,
  abevec@my-deja.com wrote:
> I created a cgi Perl script in my cgi-bin directory that is suppose to
> get executed on an "get" html command.  But the Appache server comes
> back with an error.  I'm the server administrator.  All the
> files/directories are mode 755 protected.  Any ideas how to correct
this
> problem.
> . thanks -abevec
>
> Apache Error Reponse:
>
> "Internal Server Error
>
> The server encountered an internal error or misconfiguration and was
> unable to complete your request.
>
> Please contact the server administrator, root@localhost and inform
them
> of the time the error occurred, and
> anything you might have done that may have caused the error.
>
> More information about this error may be available in the server error
> log."
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

Additional info from my error log:

[Thu Oct 12 10:59:22 2000] [error] (8)Exec format error: exec of
/home/httpd/cgi-bin/guestbook1.pl failed
[Thu Oct 12 10:59:22 2000] [error] [client 128.63.62.181] Premature end
of script headers: /home/httpd/cgi-bin/guestbook1.pl

and here is the code guestbook1.pl:

 #!/usr/bin/perl
       $temp=$ENV{'QUERY_STRING'};
       @pairs=split(/&/,$temp);
       foreach $item(@pairs) {
               ($key,$content)=split (/=/,$item,2);
               $content=~tr/+/ /;
               $content=~ s/%(..)/pack("c",hex($1))/ge;
               $fields{$key}=$content;
       }
       print "Content-type: text/html\n\n";
       print "<body bgcolor=\"#FFFFFF\">\n";
       print "<h2>$fields{'name'}</h2>\n";
       print "<pre>$fields{'comment'}</pre>\n";



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 12 Oct 2000 18:57:55 +0100
From: nobull@mail.com
Subject: Re: Changing name of file in header?
Message-Id: <u9wvfeymak.fsf@wcl-l.bham.ac.uk>

Andreas Huber <ah@datapharm.de> writes:

> how can I change the name of a file perl is sending to a browser? Can I
> do it in the header?

Please see the numerous previous threads on this (non Perl related)
subject as my answer is incomplete and there's always a long
discussion.

The "right" answer is use a Content-disposition header, but some
browsers ignore that.

The reliable answer is to tag the filename onto the URL that is used
to call the CGI in the fitst place.

http://my.server/download.cgi/somepicture.jpeg

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 12 Oct 2000 19:38:51 +0100
From: nobull@mail.com
Subject: Re: Concurrent access to data
Message-Id: <u9vguxzyys.fsf@wcl-l.bham.ac.uk>

Jeremy Mordkoff <mordkoff@xedia.com> writes:

> I either need concurrent access to my data or I need to serialize
> all access. My data is stored in flat ascii files. Up until now, I
> have relied on constructs such as that below to "guarantee" serial
> access, but every now and then I lose my data file. Is there a
> better construct to use?

Locking.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 12 Oct 2000 15:45:20 -0400
From: "M East" <smeast@kcc.com>
Subject: convert tab to comma delimited
Message-Id: <suc56jfun322c4@corp.supernews.com>

Is there an easy way to convert a tab delimited file (which contains data
fields with spaces) to a comma delimited file?  I have been searching
through the Perl Cookbook with no luck so far.

Thanks!!




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

Date: Thu, 12 Oct 2000 19:47:04 GMT
From: flint@flintslacker.com (Flint Slacker)
Subject: Re: convert tab to comma delimited
Message-Id: <39e914bf.98660489@news.tcn.net>



for(<>) {
	s/OldDelimiter/NewDelimiter/g;
	print;
}

Flint

you could do this in vi editor:

:1,$ s/	/\,/g


On Thu, 12 Oct 2000 15:45:20 -0400, "M East" <smeast@kcc.com> wrote:

>Is there an easy way to convert a tab delimited file (which contains data
>fields with spaces) to a comma delimited file?  I have been searching
>through the Perl Cookbook with no luck so far.
>
>Thanks!!
>



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

Date: 12 Oct 2000 20:00:17 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: convert tab to comma delimited
Message-Id: <slrn8uc63j.o69.bernard.el-hagin@gdndev25.lido-tech>

On Thu, 12 Oct 2000 15:45:20 -0400, M East <smeast@kcc.com> wrote:
>Is there an easy way to convert a tab delimited file (which contains data
>fields with spaces) to a comma delimited file?  I have been searching
>through the Perl Cookbook with no luck so far.

-----------------------------------
#!/usr/bin/perl -w
use strict;

$^I = '.bak';

while (<>){
	s/\t/,/g;
	print;
}
----------------------------------

Usage: skrypt.pl <file(s) to change>

>Thanks!!

You're welcome.

Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'


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

Date: Thu, 12 Oct 2000 20:11:17 GMT
From: bmccoy@chapelperilous.net (Brett W. McCoy)
Subject: Re: convert tab to comma delimited
Message-Id: <slrn8uc6pu.g7m.bmccoy@chapelperilous.net>

On Thu, 12 Oct 2000 15:45:20 -0400, M East <smeast@kcc.com> wrote:

> Is there an easy way to convert a tab delimited file (which contains data
> fields with spaces) to a comma delimited file?  I have been searching
> through the Perl Cookbook with no luck so far.

perl -pi.bak -e 's/\t/,/g' <filename>

-- 
Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
LOOK!!  Sullen American teens wearing MADRAS shorts and "Flock of
Seagulls" HAIRCUTS!


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

Date: Thu, 12 Oct 2000 20:18:22 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: convert tab to comma delimited
Message-Id: <x7itqxyfsi.fsf@home.sysarch.com>

>>>>> "BWM" == Brett W McCoy <bmccoy@chapelperilous.net> writes:

  BWM> perl -pi.bak -e 's/\t/,/g' <filename>

for simple char replacements tr is simpler and faster.

perl -pi.bak -e 'tr/\t/,/' <filename>

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 12 Oct 2000 20:28:28 GMT
From: bmccoy@chapelperilous.net (Brett W. McCoy)
Subject: Re: convert tab to comma delimited
Message-Id: <slrn8uc7q6.g7m.bmccoy@chapelperilous.net>

On Thu, 12 Oct 2000 20:18:22 GMT, Uri Guttman <uri@sysarch.com> wrote:
> for simple char replacements tr is simpler and faster.
> 
> perl -pi.bak -e 'tr/\t/,/' <filename>

That's true... I was just making sure you were paying attention ;-P

-- 
Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
Marriage, n.:
	The evil aye.


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

Date: Thu, 12 Oct 2000 13:53:53 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: convert tab to comma delimited
Message-Id: <39E624E1.30261BE1@vpservices.com>

"Brett W. McCoy" wrote:
> 
> On Thu, 12 Oct 2000 15:45:20 -0400, M East <smeast@kcc.com> wrote:
> 
> > Is there an easy way to convert a tab delimited file (which contains data
> > fields with spaces) to a comma delimited file?  I have been searching
> > through the Perl Cookbook with no luck so far.
> 
> perl -pi.bak -e 's/\t/,/g' <filename>
> 

Ok, folks that is four of you that have given a similar suggestion. 
What if the tab delimited file contains four fields that look like this:

	foo	bar	hmm, a comma	"shucks

Your "CSV" file then looks like this:

	foo,bar,hmm, a comma,"shucks

Whoops, it contains five fields if it is even parsable with the floating
quotation mark.

I will be releasing a module called AnyData.pm soon that will have a
convert() method that works between these and many other formats.  In
the meantime, this does the right thing:

#!perl -w
use strict;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new();
open(I,'<test_db.old') or die $!;
open(O,'>test_db.new') or die $!;
while ((<I>)) {
    chomp;
    my $sucess = $csv->combine( split /\t/ )
                 or die $csv->error_input();
    print O $csv->string() , "\n";

}

-- 
Jeff


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

Date: Thu, 12 Oct 2000 14:21:42 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: convert tab to comma delimited
Message-Id: <39E62B66.74AAA859@vpservices.com>

Jeff Zucker wrote:

> while ((<I>)) {

Errm, sometimes I forget that the wonderful emacs cperl-mode thinks for
me.  Belay that second set of parens.

-- 
Jeff


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

Date: 12 Oct 2000 15:25:37 -0400
From: darkon@one.net (David Wall)
Subject: Re: Cutesy Arrows - Just say nope!
Message-Id: <8FCB9AD73darkononenet@206.112.192.118>

godzilla@stomp.stomp.tokyo (Godzilla!) wrote in 
<39E5427E.401B6890@stomp.stomp.tokyo>:

>Craig Berry wrote:
>> Within the Perl community, 'cargo cult coding' refers to using 
>> some idiom or pattern without understanding why you are doing 
>> it or how it works. Frequently the code involved is identifiably
>> from some suspect source, or replicates (with bugs) a function 
>> better performed in modern Perl by a module.  
>
>
>With hopes of not reading disrespectful, your description
>perfectly and precisely defines use of modules, which are
>clearly, modern day Perl cargo cult.

I encourage you to use pencil and paper for your programming needs instead 
of re-using other people's code in the form of Perl, compilers, editors, 
operating systems, and so on. Unless you understand every single detail of 
how every single program you use works, it's obviously cargo-cult thinking 
and therefore unacceptable. But then, you should also be capable of making 
your own paper and pencils, because otherwise you're depending on 
technology supplied by other people. I hope you're good at smelting your 
own ores to get the metal to make tools.  Oh, and don't forget pottery 
skills.  Of course you'll need food while you're doing this, so bone up on 
farming and hunting as well.

No disrespect intended, of course.

-- 
David Wall
darkon@one.net


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

Date: Thu, 12 Oct 2000 19:22:13 GMT
From: micah26@my-deja.com
Subject: Erroneous Forward Slash in HTML Code by CGI.pm
Message-Id: <8s530s$vha$1@nnrp1.deja.com>

I use CGI.pm to write a lot of HTML code for me.
I installed the new CGI.pm 2.74 and found that my
HTML code had a forward slash at the end of input
fields simlilar to what you see below.
Perl:textfield('palmnum','somevalue',15,15)
HTML:<input type="text" name="palmnum"  size=15
maxlength=15 />
I do not have this problem with the CGI.pm 2.68
module.  Any ideas what could be problem?
Thanks,
Micah Gersten


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 12 Oct 2000 12:37:04 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Erroneous Forward Slash in HTML Code by CGI.pm
Message-Id: <39E612E0.BD262B31@vpservices.com>

micah26@my-deja.com wrote:
> 
> I use CGI.pm to write a lot of HTML code for me.
> I installed the new CGI.pm 2.74 and found that my
> HTML code had a forward slash at the end of input
> fields simlilar to what you see below.
> Perl:textfield('palmnum','somevalue',15,15)
> HTML:<input type="text" name="palmnum"  size=15
> maxlength=15 />
> I do not have this problem with the CGI.pm 2.68
> module.  Any ideas what could be problem?

From the CGI.pm docs:

     By default, CGI.pm versions 2.69 and higher emit XHTML 
     (http://www.w3.org/TR/xhtml1/). The -no_xhtml pragma 
     disables this feature.

XHTML uses a slash on tags that don't have end tags. It shouldn't matter
in this case since AFAIK all browsers will display the tags with the
trailing slash as long as there is a space before it.

-- 
Jeff


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

Date: Thu, 12 Oct 2000 15:37:43 -0400
From: "steveFarris" <nlymbo@mindspring.com>
Subject: hash value to XML::Parser handler
Message-Id: <8s53t6$srm$1@slb7.atl.mindspring.net>

Hi, could someone give me a general overview of what is going on with the
%context variable int the xml handlers?? I seems to take on some magical
values.


    require XML::Parser;
    import XML::Parser;
    my %context;
    my $p = new XML::Parser (

        Handlers => {
     Start => sub {xml_start(\%context, @_[1..$#_])},
     End =>  sub {xml_end(\%context, @_[1..$#_])},
     Char =>  sub {xml_char(\%context, @_[1..$#_])},
        }
        );


    eval {
 $p -> parsefile($path);
    } ;
    if ($@) {
 warn $@;
    }

    return 1;
}


sub xml_start {
    my ($context, $tag, %attrs) = @_;


    push (@{$context->{'tagcontext'}}, $tag);
    $context->{'context'} = join("/", @{$context -> {'tagcontext'}});

    if ($context->{'context'} =~ /(author|bill_topic)$/) {
 push(@{$context->{"data:$1"}}, $attrs{'id'});
    }

    if ($tag eq 'p') {
 print "<P";
 if (%attrs) {
     foreach (keys %attrs) {
  print " $_=$attrs{$_}";
     }
 }
 print ">";

    } elsif ($tag eq 'add') {
 print "[A&gt;<I>";

    } elsif ($tag eq 'del') {
 print "[D&gt;<STRIKE>";

    } elsif ($context->{'context'} =~ m=
 (?:bill_key/.+|
  author/display_name|
  billtext_version|
  billtext_version_date
  )
 $=x) {

 $context->{'storing'} = 1;
    }
}

sub xml_end {
    my ($context, $tag) = @_;

    if ($tag eq 'p') {
 print "</P>";
    } elsif ($tag eq 'add') {
 print "</I>&lt;A]";
    } elsif ($tag eq 'del') {
 print "</STRIKE>&lt;D]";
    }

    if ($context->{'storing'}) {

 if ($context->{'context'} =~ m=bill_key/state=) {
     print "<B>$context->{'cache'} ";
 } elsif  ($context->{'context'} =~ m=bill_key/bill_number=) {
     print "$context->{'cache'}</B><BR>\n";
 } elsif  ($context->{'context'} =~ m=bill_key/=) {
     print "$context->{'cache'} ";
 } elsif  ($context->{'context'} =~ m=author/display_name=) {
     print "<B>AUTHOR: </B> $context->{'cache'}<BR>\n";
 } elsif  ($context->{'context'} =~ m=billtext_version$=) {
     print "<B>VERSION: </B> $context->{'cache'}<BR>\n";
 } elsif  ($context->{'context'} =~ m=billtext_version_date$=) {
     $context->{'cache'} =~ s-(\d{4})(\d{2})(\d{2})-$2/$3/$1-;
     print "<B>VERSION DATE: </B> $context->{'cache'}<BR>\n";
 }
 $context->{'storing'} = 0;
 $context->{'cache'} = '';
    }

    pop (@{$context->{'tagcontext'}}); # happy, happy XML
    $context->{'context'} = join("/", @{$context -> {'tagcontext'}});
}

sub xml_char {
    my ($context, $char) = @_;
    if ($context->{'storing'}) {
 $context->{'cache'} .= $char;
    } elsif ($context->{'context'} =~ m-/p(/|$)-) {
 # Just spew paragraph content
 print $char;
    }
}

1;








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

Date: Thu, 12 Oct 2000 19:29:00 GMT
From: Michael Segulja <michael.segulja@sgi-lsi.com>
Subject: Re: Help with newbie question
Message-Id: <8s53di$vv3$1@nnrp1.deja.com>

In article <Pb5F5.19$T3.170882560@news.frii.net>,
  cfedde@u.i.sl3d.com (Chris Fedde) wrote:

> To check that a row is in the database use sql like
>
>     select count(title) from mp3main where title = ?;
>
> You need to prepare this into another statement handle then execute
> and fetch on it.  It will return a row with one column containing
> the number of matches.  Read up on the fetchrow_* DBI methods.
> You should probably also check the return values of the $sth->execute
> statements.  otherwise you might not know if there has been an error.

Okay, this got me pointed in the right direction, so thank you very
much for your help.  I'm still trying to figure out what I should do,
so maybe somebody can see if what I have is right or not.  Here's what
I have so far:

#!/usr/bin/perl -w

use diagnostics;
use strict;
use MP3::Info;
use File::Find;
use DBI;

my $mp3dir = "/var/audio/mp3";

print "\n" x 3;
print "Scanning $mp3dir and entering songs into database... \n";

&insert_mp3;

print "\nDone\n";

# Subroutine to insert mp3 info into the database.
sub insert_mp3 {
	my ($title, $artist, $album, $year, $comment, $genre);
	my ($durationM, $durationS, $bitrate, $version, $layer);
	my @files;

	my $db = "mp3db";
	my $host = "localhost";
	my $user = "mp3";
	my $password = "mp3pass";

	# Find the MP3 files.
	find sub {push @files, $File::Find::name if /\.mp3\z/ && -f,},
$mp3dir;

	foreach my $mp3file(@files) {
		my $info = get_mp3info($mp3file);
		my $tag = get_mp3tag($mp3file);
		if ($tag) {
			($title, $artist, $album, $year, $comment,
$genre) =
			@{$tag}{qw(TITLE ARTIST ALBUM YEAR COMMENT
GENRE) };
		}

		$durationM = $info->{MM};
		$durationS = $info->{SS};
		$bitrate = $info->{BITRATE};
		$version = $info->{VERSION};
		$layer = $info->{LAYER};

		# Connect to database.
		my $dbh = DBI->connect
("DBI:mysql:database=$db;host=$host", $user, $password,
			{RaiseError => 1} ) || die "Cannot make
connection to database: $DBI::errstr";

		# Check for duplicates.
		my $sth = $dbh->prepare("SELECT count(title) FROM
mp3main
				WHERE title = ?") || die "Cannot
prepare SQL statement: $dbh->errstr";

		$sth->execute($title);
		my @ary = $sth->fetchrow_array;


		# If title is 0, insert into database, otherwise do
nothgin.
		if  (@ary == 0) {
			$sth = $dbh->prepare("INSERT INTO mp3main
					(album, artist, title, genre,
comment, bitrate, version,
					mpeg_layer, durationM,
durationS, year)
					VALUES
(?,?,?,?,?,?,?,?,?,?,?)" )
					|| die "Cannot insert data:
$dbh->errstr";
		}
		else {
			do_nothing;
		}

		# Disconnect from database.
		$dbh->disconnect();
	}
}

I'm checking to see if a row is in the database, and if it is I want
the script to do_nothing, except that I don't know what that should be
exactly.  Right now, it just stops without adding any songs that I have
added since initially running the script.


>
> BTW, Are you sure that title is unique for all albums and artists?
>
> chris
> --
>     This space intentionally left blank
>


And this is something else I thought about.  The title could be the
same on different albums, and possibly the same title on different
albums with the same artist.  I probably should be checking for
duplicates with the title, album, and artist, but right now I'm just
trying to get one thing to work.


Thanks so much for you help,

Michael


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 12 Oct 2000 21:52:07 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: Help with newbie question
Message-Id: <boqF5.52$T3.170883072@news.frii.net>

In article <8s53di$vv3$1@nnrp1.deja.com>,
Michael Segulja  <michael.segulja@sgi-lsi.com> wrote:
>
>  I'm still trying to figure out what I should do,
>
>And this is something else I thought about.  The title could be the
>same on different albums, and possibly the same title on different
>albums with the same artist.  I probably should be checking for
>duplicates with the title, album, and artist, but right now I'm just
>trying to get one thing to work.
>

I guess that I'll chime in again on this...

Some database engines allow primary keys to include multiple columns.  In the
case of your data I'd guess that a key that includes album, title and
artist could be enough. 

It seems that you should try running the program under the debugger to see if
it is really giving you what you think that it is.  

Good luck!
chris
-- 
    This space intentionally left blank


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

Date: Thu, 12 Oct 2000 18:51:18 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: hoe to alter @INC?
Message-Id: <39E607D0.C60E91AC@netstorm.net>

"Andrew N. McGuire" wrote:
> 
> On Thu, 12 Oct 2000, Jim Mauldin quoth:
> 
> JM> "Andrew N. McGuire" wrote:
> JM> >
> JM> > On Thu, 12 Oct 2000, Jim Mauldin quoth:
> JM> >
> JM> > JM> cen09220 wrote:
> JM> > JM> >
> JM> > JM> > Rafael Garcia-Suarez wrote:
> JM> > JM> > >
> JM> > JM> > > Werner, Wolfgang wrote in comp.lang.perl.misc:
> JM> > JM> > > >hi,
> JM> > JM> > > >how can i change @INC?
> JM> > JM> > > >i wan to have a new dir for modules
> JM> > JM> > > >thans
> JM> > JM> > >
> JM> > JM> > > The preferred way to do this is to add at the beggining of your scripts:
> JM> > JM> > >   use lib '/new/dir/for/modules';
> JM> > JM> >
> JM> > JM> > Why is that better than pushing the path onto @INC?
> JM> > JM>
> JM> > JM> Modules specified by a 'use' declaration are loaded during compilation,
> JM> > JM> before the program begins to execute.  So even if you push something
> JM> > JM> onto @INC as the very first statement of your program, it's already too
> JM> > JM> late.
> JM> >
> JM> > That is not true, IIRC, you can unshift the directory onto @INC in a
> JM> > BEGIN {} block to achieve the same effect.
> 
> JM> Your statement is probably better written as "true unless you unshift
> JM> the directory into a BEGIN block".  But use lib has other advantages as
> JM> well, including simplicity.
> 
> I think my statement is clear as written, how do you unshift a directory
> ( or list of strings that represents a list of directories ) into a BEGIN
> block?  The first argument to unshift is an array, not a block.  I am
> aware of the other advantages of 'use lib', but the advantage you pointed
> out, is not a valid one, I am afraid. :-)
> 
I meant, of course "unshift into @INC in a BEGIN block" (and you're
right to stick it to me for my carelessness) but the focus was on the
"true unless" part.  My valid point to you was that in the normal course
of events shift @INC won't work, and that modules are no longer an
extension of Perl, but an integral part of it, and should be used rather
than hacking workarounds.

-- Jim


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

Date: Thu, 12 Oct 2000 14:02:32 -0700
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: How can I add 5 hours to the time my server reports?
Message-Id: <121020001402323182%lincmad001@telecom-digest.zzn.com>

In article <u966my0y2p.fsf@wcl-l.bham.ac.uk>, <nobull@mail.com> wrote:

> "Ben Graves" <ben.graves@virgin.net> writes:
> 
> > How do I add five hours to the time it reports in a way that also changes
> > the date?
> 
> Set $ENV{TZ} to the appropriate zone before calling localtime().
> Details of the syntax/semantics of $ENV{TZ} are OS dependant but
> you'll probably find 'GMT0BST' works for the UK timezone.

I didn't see the original post, but if I understand the reply, the OP
is trying to take a time/date displayed in U.S. Eastern Time Zone and
display it in U.K. standard time (GMT/British Summer Time).

Besides being the most direct method, setting the time zone as shown
above also has the advantage that it should adjust for daylight savings
on the correct dates -- the U.S. and U.K. dates differ slightly. The
U.S. begins on the first Sunday of April, while the U.K. (and the rest
of the E.U.) begin on the last Sunday of March.

> > I would like it to display the date in the following format;
> > Mon 5th September, 2000
> 
> See the discussion of time formating in perldoc -f localtime


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

Date: Thu, 12 Oct 2000 12:59:37 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: interpreting hidden backslash constructs
Message-Id: <MPG.144fb8068d643cd898ae30@nntp.hpl.hp.com>

In article <39E59A5E.85C44A16@eyp.ee> on Thu, 12 Oct 2000 13:02:54 
+0200, Risto Vaarandi <risto.vaarandi@eyp.ee> says...
> in perl many special characters can be expressed
> with backslash construct (\n means newline, \t is
> tabulation etc.).
> How can i force perl to interpret these backslash
> constructs if they are hidden inside a variable:

I published a solution just last week, which handles these escapes and 
many others.

http://x57.deja.com/[ST_rn=ps]/getdoc.xp?AN=677178148

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 12 Oct 2000 12:08:04 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: ip under win9x/2k from the commandline?
Message-Id: <MPG.144fabf093b8b5d098ae2d@nntp.hpl.hp.com>

[Rearranged for logical flow, and signature clipped, in accordance with 
the conventions of this and most other newsgroups.]

In article <39E587FE.A4682572@gmx.de> on Thu, 12 Oct 2000 11:44:30 
+0200, Werner, Wolfgang <zakazan@gmx.de> says...
> jason wrote:
> 
> > Werner, Wolfgang wrote ..
> > >how can i find ount my ip using the windows commandline and perl?
> >
> >   perl -MSocket -e"print inet_ntoa inet_aton $ENV{COMPUTERNAME}"
> >
> hi jason,
> nope, seems not to work on my machine.
> any idea?
> thakns for your time anyway :)

perlfaq9: "How do I find out my hostname/domainname/IP address?"

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 12 Oct 2000 19:29:55 GMT
From: steveo@panix.com (Steven M. O'Neill)
Subject: Re: ip under win9x/2k from the commandline?
Message-Id: <8s53fj$nmo$1@news.panix.com>

Werner, Wolfgang <zakazan@gmx.de> wrote:
>jason wrote:
>
>> Werner, Wolfgang wrote ..
>> >how can i find ount my ip using the windows commandline and perl?
>>
>>   perl -MSocket -e"print inet_ntoa inet_aton $ENV{COMPUTERNAME}"

>hi jason,
>nope, seems not to work on my machine.
>any idea?
>thakns for your time anyway :)

perl -e "system (ipconfig)"
-- 
Steven O'Neill                                         steveo@panix.com


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

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


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