XML::Writer....Lessons Learned

2007-04-27 Thread Dave Adams

Because I am not a very good perl programmer (but working on it) an unable
to answer most of the questions from the group, I thought I could at least
contribute what I have learned so I can help others that are in my position.

Today I learned something about XML::Writer where I was using single quotes
instead of double quotes and it caused me all sorts of problems later in the
script.  Here is my corrected code:

use strict;
use CGI;
use CGI::Carp;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(escapeHTML);
use XML::Writer;
use IO::File;

my $output = new IO::File(">test.xml");
my $writer = new XML::Writer(OUTPUT => $output);
$writer->startTag("greeting","class" => "simple");  # It was here that I was
using singles instead of doubles and it caused problems later on.
$writer->characters("Hello, world!");
$writer->endTag("greeting");
$writer->end();
$output->close();

my $page = new CGI;
my $htmldoc;
$htmldoc .= "Testing Testing";
print $page->header;# create the HTTP header
print $page->start_html('TEST PAGE'); # start the HTML
print $htmldoc;
print $page->end_html;

Thanks to people in the group who have helped me.  It is a great resource.


XML::Writer creates a file but fails to be recognized

2007-04-26 Thread Dave Adams

When generating a file with XML::Writer the script certainly builds the file
but when I go to test for it, it fails.  Does anyone have a reason why?  How
do I create a file that I can use in the rest of my script?

use XML::Writer;
use IO::File;
my $output = new IO::File(">test.xml");
my $writer = new XML::Writer(OUTPUT => $output);
$writer->startTag("greeting","class" => "simple");
$writer->characters("Hello, world!");
$writer->endTag("greeting");
$writer->end();
$output->close();

#Test to make sure this file exist before preceding
if (! -r $output) {
   print ("ERROR:  can't read /$output XML file.");
}


Not an ARRAY reference. Problems reading a simple XML file

2007-04-02 Thread Dave Adams

My script is having problems reading and XML file with only one record in
it.  When I add two or more records, there are no problems.  The error is
"Not and ARRAY reference.."

Here is the PROBLEM xml file (test.xml):




FBIS2004
CP1




Here is the WORKING xml file:




FBIS2004
CP1


FBIS2005
CP2



Here is my script:

#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;

$xml = new XML::Simple (KeyAttr=>[]);
$data = $xml->XMLin("test.xml");
#print Dumper($data);
print "There are " . scalar(@{$data->{RECORD}}) . " records.\n";
foreach my $var (@{$data->{RECORD}})
{
print $var->{DOCI} . "\n";
print $var->{COLLNAME} . "\n";
}

Does anyone have an explaination for this?

Thanks in advance,
DA


Re: How do I generate a hash from an xml document?

2007-03-27 Thread Dave Adams

#
#
#
# FBIS2004
# CP1
#
#
# FBIS2005
# CP2
#
#


#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;

# create object
$xml = new XML::Simple (KeyAttr=>[]);

# read XML file
$data = $xml->XMLin("datafile.xml");

# dereference hash ref
# access  array

foreach $e (@{$data->{RECORD}})
{
print "doci: ", $e->{DOCI}, "\n";
print "collname: ", $e->{COLLNAME}, "\n";
print "\n";
}

# Puts XML file into hash
my %starrecords=();
foreach $e (@{$data->{RECORD}})
{
$starrecords {$e->{DOCI}} = $e->{COLLNAME} ;
}

# Prints the hash
print "Hash Output: \n";
foreach my $key_value_pairs (%starrecords) {
print "$key_value_pairs";
}
print "\n";

# Prints the keys of the hash
print "Hash Keys Output: \n";
foreach my $key_values (keys %starrecords) {
print "$key_values\n";
}

# Prints the values of the hash
print "Hash Values Output: \n";
foreach my $value_values (values %starrecords) {
print "$value_values\n";
}




On 3/26/07, Rob Dixon <[EMAIL PROTECTED]> wrote:


Dave Adams wrote:
>
> What are the general steps to building a hash from and xml document?
>
> Here are my steps:
>
> 1. Read in xml document using XML::Simple
> 2. Create and empty hash
> 3. Loop through $VAR1 (the anonymous datastructure) and populate hash
>
> Is this the general idea or is there a simplier way?

Hi Dave

The result of XMLin is already a reference to a hash representation of
the XML. If you're looking at the XML::Simple documentation that says
you can dump the hash using Data::Dumper then that's not a part of
using XML::Simple - it's just a way of examining the hash data so that
you can see what you've got.

HTH,

Rob



How do I generate a hash from an xml document?

2007-03-26 Thread Dave Adams

What are the general steps to building a hash from and xml document?

Here are my steps:

1. Read in xml document using XML::Simple
2. Create and empty hash
3. Loop through $VAR1 (the anonymous datastructure) and populate hash

Is this the general idea or is there a simplier way?

Thanks to all,
DA


Getting number of children of the root in an XML object

2006-03-31 Thread Dave Adams
I am trying to get the number of children of the root element and my script
gives me the number of children of the children instead.

Here is my XML document (ejournlist.xml):



  
  Africa Confidential
  Vol. 1, no.1
  PDFformat
  
  
  Time Magazine
  Vol. 1, no.1
  TXTformat
  




Here is my perl script:

#!/usr/bin/perl -w
use XML::Simple;
#create object
my $xml = new XML::Simple;

#read XML file
my $data = $xml->XMLin("ejournlist.xml");

my $ejourn_cnt = scalar(keys %{$data->{'EJOURN'}});
print "The number of EJOURNs is: $ejourn_cnt \n";

*The scripts returns 3 when it should return 2.*

Any advice would be appreciated.

DA

**


Really simple XML question

2006-03-31 Thread Dave Adams
How do I print the value of 'Time Magazine'?

Here is my file (ejournlist.xml):




 Africa Confidential
 Vol. 1, no.1
 PDFformat


 Time Magazine
 Vol. 1, no.1
 TXTformat



Here is my script:

#!/usr/bin/perl -w
use XML::Simple;
use Data::Dumper;

#create object
my $xml = new XML::Simple;

#read XML file
my $data = $xml->XMLin("ejournlist.xml");

#print output
print Dumper($data);


Counting specific elements in a XML object

2006-03-30 Thread Dave Adams
If I have a xml file like the following:



John Doe
43
M
Recieving


Bob Gordon
50
M
Shipping



Is there some perl module out there that can help me get the number of
employees or in other words, the number occurences of ""?

I guess I can get it conventionally by reading in the file and doing a count
every time the script encounters "".  But there must be an easier way.

Any ideas?

DA


File Test Question

2005-11-30 Thread Dave Adams
*My Code:*

my $logfile = "logfile_with_content";
if (-w $logfile) {
print ("True - file exists but empty");
}
if (-s $logfile) {
print ("True - file exist and has content");
}

*My Output:*

True - file exists but empty True - file exist and has content

*My Question:*

Why do both test evaluate to true when the file called
"logfile_with_content" is 5K in size?  I would expect the second file test
to only work?  Any advice?

Thanks


Troubles getting a value out of an XML object

2005-10-24 Thread Dave Adams
I am having troubles getting a value out of an XML object.

*Here is my object:*
my $xml = new XML::Simple;
my $data = $xml->XMLin($ResponseDoc);

*Here is the script asking for a snippet of data:*

print Dumper($data->{CreateLock});
**
*Here is the output:*

$VAR1 = { 'DatabaseId' => 'db1', 'RecordNumber' => '23617', 'Id' => 'test'
};
*Question:* How do I get the value of RecordNumber?
 Thanks in advance.
Dave Adams


Carriage Return and LineFeeds Question

2005-10-20 Thread Dave Adams
I am having troubles understanding how perl sees carriage returns and line
feeds. I am not sure if it is a windows and unix thing.

*Scenario:* I have a HTML form that uploads a text file (via a POST) to a
unix server who then passes it to a perl cgi. This cgi parses through the
file, puts it in an array and if it encounters a paragraph break, I want it
to insert "^P".


*My Sample text file:
*
This is my first paragraph.

This is my Second paragraph.


*My code:*
#!/usr/bin/perl -w
use CGI qw(:standard);
use IO::Handle;
use File::Temp qw /tempfile /;
use Text::Wrap;

my $cgiobject = new CGI;

my $upload_dir = "/temp/";

my $filename_txt = $cgiobject->param("UPLOADFILE");

$filename_txt =~ s/.*[\/\\](.*)/$1/;

open (UPLOADFILE, ">$upload_dir/$filename_txt");
binmode UPLOADFILE;
while ( <$upload_filehandle_txt> )
{
print UPLOADFILE;
}
close UPLOADFILE;

open(UPLOADFILE, "$upload_dir$filename_txt") || die "problem: $!";
my @textfile_contents = ;
close UPLOADFILE;


##Here is where my problem lies
##When perl reads in the scalar to push it on to my array, how do I
##get it to replace the paragraph breaks with ^P?

my @body = ();
for (my $i=0; $i<=$#textfile_contents; $i++) {
push(@body, $textfile_contents[$i]);
}
  Thanks again for all the contributors on the list.
Dave Adams


Re: Identifying or finding paragraphs

2005-10-14 Thread Dave Adams
How paragraphs are delimited is actually my question.  In otherwords,
when perl reads in my string, can it identify where the paragraphs
breaks are?

In my example, $text was created in wordpad where 'This is the FIRST
paragraph' and 'This is the SECOND paragraph' are seperated by a
paragraph break.

My desired output is: This is the FIRST paragraph^PThis is the SECOND paragraph

Thank you for your interest and your efforts to help me out.  Very
much appreciated.
DA

On 10/14/05, Xavier Noria <[EMAIL PROTECTED]> wrote:
> On Oct 14, 2005, at 16:13, Dave Adams wrote:
>
> > Question: How do you find a paragraph break in perl?
> >
> > Synopsis:  In a string I need to find the paragraph breaks and replace
> > it with a ^P.  Here is my code.
>
> How are paragraphs delimited? Can you give an example with a couple
> of paragraphs and the output you'd like to get?
>
> -- fxn
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Identifying or finding paragraphs

2005-10-14 Thread Dave Adams
Question: How do you find a paragraph break in perl?

Synopsis:  In a string I need to find the paragraph breaks and replace
it with a ^P.  Here is my code.

#!/usr/bin/perl -w
use strict;
use Text::Wrap;

$my text = 'This is the FIRST paragraph.
This is the SECOND paragraph.';

print wrap("\t","^P","$text");

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Simple Substition Question

2005-10-13 Thread Dave Adams
My Code:
--
#!/usr/bin/perl -w
use strict;
my $text= 'hello';
my $text2 = 'bye';
my $text3 =~ s/$text/$text2/g;
print $text3;

My Error:
---
F:\perlex\findpara.pl line 5.
Use of uninitialized value in print at F:\perlex\findpara.pl line 6.

My Questions:
---
Should perl give me a true or false? I am confused by this error.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Anonymous Reference Question

2005-09-28 Thread Dave Adams
When I do this:

#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $grades = {"tom"=> 50, "sally"=> 60, "harry" => 70};
print Dumper($grades) ;


And perl gives me this:

$VAR1 = {
  'harry' => 70,
  'sally' => 60,
  'tom' => 50
};


QUESTION: Does this mean that $grades is an anonymous reference
because perl gives is $VAR1?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Shift Question

2005-09-27 Thread Dave Adams
QUESTION: What is the purpose of the line "my $msg = shift;"?  I am
guessing it is for the @_ array but what list element is there to be
shifted off?  It seems that the shift function is in a lot of
subroutines and I am confused as to their purpose.

#!/bin/perl -w
(my $PROGNAME = $0) =~ s/^.*\///;
(my $SHORT_PROGNAME = $PROGNAME) =~ s/\.pl$//;
my $SYSLOG_PRIORITY = 'info';
my $SYSLOG_FACILITY = 'local4';

use Sys::Syslog;

sub write_log($) {
#   write a datestamped message to the logfile, e.g.:
#   &write_log('some message');

my $msg = shift;

#   print message to logfile:
openlog($SHORT_PROGNAME,'pid','');
syslog("$SYSLOG_FACILITY|$SYSLOG_PRIORITY", '%s', "$msg");
closelog();

}
$teststring = 'Test Msg to SysLog';
write_log($teststring);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Good Intro reading

2005-09-26 Thread Dave Adams
Being a junior perl programmer, I read a lot of docs and I came across
a really good site that is well written and structured.  If you are
just starting out, I would highly recommend it.

http://www.wdvl.com/Authoring/Languages/Perl/PerlfortheWeb/toc.html

My compliments to Aaron Weiss, the author.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Looking for perl scripts to remove ^M

2005-09-23 Thread Dave Adams
Sometimes I get perl scripts that were developed on windows and then
brought over to UNIX and the scripts contain all the pesky
metacharacters of ^M and excessive blank lines.

Does anyone have a simple script to clean these files up or suggestions?

My appreciation in advance,
DA

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Is it possible to force a particular order in a hash?

2005-09-22 Thread Dave Adams
I have a hash that I need to use later and display some values in a
particular order.  Perl comes up with its own way of ordering it but I
am wondering if I can instruct perl to have it listed in the way that
I want.

Here is the code


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

my $page = {
AUTHOR=>"John Smith",
LANGUAGE=>"English",
TITLE=>"Treasure Island"};

print ref($page). "\n";
print $page->{AUTHOR} . "\n";

print keys %{$page};
print "\n";
print sort (keys %{$page});


Here is the output:

HASH
John Smith
LANGUAGETITLEAUTHOR
AUTHORLANGUAGETITLE


Here is my desired output:

TITLEAUTHORLANGUAGE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How do you force SOAP::Lite to use document/literal SOAP messages?

2005-09-02 Thread Dave Adams
I am trying to write a simple SOAP client written in perl and to talk to a 
webservice written in .NET. I am unsuccessful. I believe the web service is 
expecting document/literal SOAP messages but I think the SOAP::Lite module 
sends stuff in RPC/encoded messages.
 Is there any way of telling? Or, even better, is there a way to force the 
SOAP::Lite module to use document/literal messaging?
 Since everyone like to see some code, here it is:
 *The Web Service (in .NET):*

[WebMethod]
public string HelloWorld()
{
   return "Hello World";
}

*The Client:*

use SOAP::Lite;

my $soap = SOAP::Lite
-> uri('http://www.alfredbr.com')
-> on_action( sub { join '/', 'http://www.alfredbr.com', $_[1] } )
-> proxy('http://localhost/Example1/Service1.asmx');

print $soap->HelloWorld()->result;


Re: References Question

2005-08-19 Thread Dave Adams
Dan,

It appears the $apple->[2] and $apple[2] are not the same thing.


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

my $apple = [4,5,6]; #example of a scalar representing an array

print ref($apple) . $apple->[2] . "\n";
print ref($apple) . $apple[2] . "\n";


errror msg:

Global symbol "@apple" requires explicit package name at
F:\perlex\Perl-1.pl line 7.
Execution of F:\perlex\Perl-1.pl aborted due to compilation errors.

On 8/19/05, Dan Klose <[EMAIL PROTECTED]> wrote:
> Hello again,
> 
> for an intriduction to refs check chapter 1 of advance perl programming
> by Srinivasan & O'Reilly Press.  Its very quick and very clear.
> 
> On Fri, 2005-08-19 at 10:31 -0400, Dave Adams wrote:
> > In the code below, I thought $array[2] and $array->[2] were different
> > but they give me the same result.
> >
> > Any explaination for this?
> >
> Try this: untested - and i don't usually use refs.
> > my @array = (1,2,3);
> my $array_ref = [EMAIL PROTECTED]
> > my $array [EMAIL PROTECTED];
> #Not sure what this does below.
> > print ref($array);
> print @$array_ref[2];
> > print $array[2];
> > print $array->[2];
> >
> --
> Daniel Klose
> PhD Student - Taylor Group
> Mathematical Biology
> National Institute for Medical Research
> The Ridgeway
> Mill Hill
> London
> NW7 1AA
> 
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




References Question

2005-08-19 Thread Dave Adams
In the code below, I thought $array[2] and $array->[2] were different
but they give me the same result.

Any explaination for this?

my @array = (1,2,3);
my $array [EMAIL PROTECTED];
print ref($array);
print $array[2];
print $array->[2];

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




strftime Problem

2005-08-09 Thread Dave Adams
I am trying to get the date stamps of multiple files on a win32
machine using the strftime function in a foreach loop.

For testing purpose, I take a single file and get the modification
time of it.  This works.

I then recycle my code and place it in a foreach loop.  This fails.

Error message is: 
Usage: POSIX::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -
1, isdst = -1)

Here is my code:

#!/usr/bin/perl -w
use strict;
use Time::localtime;
use Date::Calc qw(:all);
use File::stat;
use POSIX qw(strftime);

#WORKS
my $file = 'D:\BACKUPS\LOGS\S839.LOG';
my $s = stat($file) || die "Can't stat($file) $!\n";
my $modtime = strftime('%Y-%m-%d', localtime($s->mtime));
print($modtime);


#FAILS.
my $dblogfile_dir = 'D:\BACKUPS\LOGS';
opendir(DH, $dblogfile_dir) or die "could not open directory: $!";
my @files = grep(!/^\.\.?$/, readdir(DH));

foreach my $member (@files) {
my $file = "$dblogfile_dir\\$member";
my $s = stat($file) || die "Can't stat($file) $!\n";
my $modtime = strftime('%Y-%m-%d', localtime($s->mtime));
print($modtime);
}
closedir(DH);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Getting Date Stamp of a file on a Win32 System

2005-07-29 Thread Dave Adams
Robert,

Thanks very much.  It works great.  Your code was nice and simple.

Much appreciated.
DA

On 7/28/05, Robert <[EMAIL PROTECTED]> wrote:
> I found this maybe it will help:
> 
> 
>use strict;
>use File::stat;
>use POSIX qw(strftime);
> 
> 
>my $file = 'test.txt';
> 
> 
>my $s = stat($file) || die "Can't stat($file) $!\n";
> 
> 
>my $modtime = strftime('%Y-%m-%d', localtime($s->mtime));
> 
> 
>print "Modification time of $file is $modtime\n";
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Getting Date Stamp of a file on a Win32 System

2005-07-28 Thread Dave Adams
On a Win32 system, how do you get a date stamp of a file?

I used: 

#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use File::stat;
my $filename = "test.txt";
my $stat = stat($filename);
print Dumper($stat);
my $modified_time = stat($filename)->mtime;
print ("The modified time of $filename is: $modified_time");

But this only gets me time.  Nothing in the element list for STAT
seems to give me the date.

Any suggestions?
Thanks in advance.
DA

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




IF statements and modules - do they mix?

2005-07-26 Thread Dave Adams
Does perl allow you to conditionally include a module?

For example:

#!/usr/bin/perl -w
use strict;
my $DEBUG = 0;
if (DEBUG) {
use diagnostics;
}
my $filename = "test$$.txt";
open (FH , ">$filename") || die "error: $!";
print (FH "hi");
close (FH);

Although this is a simple and silly example, it would be nice to be
able to include the diagnostic module by setting my debug to true.

Any Comments?
DA

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




What does "unblessed reference" mean?

2005-07-26 Thread Dave Adams
I got this error that reads something like: Can't call method "print"
on unblessed reference at {script name} ,  chunk 1.

In general terms, can anyone tell the what this is about so I can comb
through my script and fix this problem.

Thanks in advance,
Dave Adams

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Control Structure Question

2005-07-22 Thread Dave Adams
The following code looks too rigid, how can I achieve the same result
using one of the control structure (foreach, for, etc)?


#!/usr/bin/perl -w
use strict;
use Date::Calc qw(:all);

my @today = Today();
my $year_now = $today[0];
my $month_now = $today[1];
my $day_now = $today[2];

print ($year_now);
print ("===\n");
print ($month_now);
print ("===\n");
print ($day_now);
print ("===\n");

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Problems creating a simple variable

2005-07-21 Thread Dave Adams
I want to create a variable, to be used for other stuff, using today's date.

Can anyone help me with the second last line?

use Time::localtime;
my $tm = localtime;
printf("The current date is
%04d%02d%02d\n",$tm->year+1900,($tm->mon)+1, $tm->mday);
my $currentdate = ??
print ($currentdate);


HSCH (Hope Someone Can Help)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Problems getting current time

2005-07-19 Thread Dave Adams
You are right.

I thought it was something more because I got an error: 

Can't locate object method "hours" via package "Time::tm" (perhaps you forgot to
 load "Time::tm"?) at ./GetDate.pl line 4.

I was also using the Orielly Perl CookBook 2nd Edition and it
specifies $hours and not $hour.

This is very frustrating for a beginner when the text book is wrong.

Thank you very much for the help.

DA


On 7/19/05, Wiggins d'Anconia <[EMAIL PROTECTED]> wrote:
> Dave Adams wrote:
> > I can get date but not time.
> >
> > use Time::localtime;
> > $tm = localtime;
> > printf("Current date: %04d-%02d-%02d\n",$tm->year+1900,($tm->mon)+1, 
> > $tm->mday);
> > printf("Current time: %02d:%02d:%02d\n",$tm->hours,$tm->min,$tm->sec);
> 
> The above should include $tm->hour instead of $tm->hours, but were you
> not getting the min/sec before?
> 
> >
> > Any help would be appreciated.
> > DA
> >
> 
> http://danconia.org
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Problems getting current time

2005-07-19 Thread Dave Adams
I can get date but not time.

use Time::localtime;
$tm = localtime;
printf("Current date: %04d-%02d-%02d\n",$tm->year+1900,($tm->mon)+1, $tm->mday);
printf("Current time: %02d:%02d:%02d\n",$tm->hours,$tm->min,$tm->sec);

Any help would be appreciated.
DA

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: reading a big file

2005-07-19 Thread Dave Adams
Can you use some sort of 'tail' command to get the last lines?

DA

On 7/16/05, Wiggins d'Anconia <[EMAIL PROTECTED]> wrote:
> Octavian Rasnita wrote:
> > Hi,
> >
> > I need to create a program which reads a file from the LAN, and that file is
> > continuously updated (kind of log).
> > The file increases continuously, and it can become very big.
> >
> > On every read, I need to read just the lines for the current day (which is
> > specified in each line) and jump over the lines from the previous days.
> >
> > The problem is that if I just open() the file and verify each line to see if
> > it is a good one, takes very much time, and I need to find a faster
> > solution.
> >
> > Checking each line might take a long time, but I think that verifying each
> > line means downloading the whole content of the file on my computer, and
> > this will also make the program lose much time.
> >
> > Do you have any idea what can I do to make the program run faster?
> >
> > I am thinking to make the program in such a way that after the first run, it
> > gets the line number of the first line from the current day, or the number
> > of the first bit of the start of that line, then on next times it runs, it
> > jumps directly to that line somehow (?), or directly to that bit (using
> > seek), but I don't know if in that case the content of the file won't be
> > also downloaded to my computer.
> >
> > Do you have any idea how I can download just a part of a file from the
> > network?
> >
> 
> If my understanding is correct that would have to be something built
> into the protocol of whatever network protocol you are using. Your seek
> idea should be correct, and I know for instance modern FTP servers have
> the ability to seek to a different part of a file, in which case the FTP
> server only provides that remaining portion of the file on a get (this
> is how pause/resume downloaders are implemented). And some HTTP servers
> have this capability. You should probably check with the protocol docs
> to see if it has the capability. Assuming the protocol is advanced
> enough then it should respect a seek and not provide the whole file. The
> best thing to do in this kind of case is to setup some sort of network
> monitoring and then just try it. See if you open a large file, seek to a
> location near the end and then see if the network gets slammed or if
> only the small sample of file is sent.
> 
> perldoc -f seek
> 
> For more info.
> 
> > Help!
> >
> > Thank you.
> >
> > Teddy
> >
> 
> Good luck,
> 
> http://danconia.org
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Komodo Question: How do you install a local copy of perl documentation?

2005-07-13 Thread Dave Adams
I am behind a firewall and I cannot get out to the internet and I want
to integrate a local copy of perl documentation in the the IDE of
Komodo, but the default is for it to go out to the internet to get it.

Does anyone know how to configure this?

Thanks in advance,
Dave Adams

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Finding the value of a key in a hash

2005-07-12 Thread Dave Adams
 %vegetable_costs  = (Beans  => 300
   Carrots => 200,
   Apple   => 250 );

To get the value of the key called Beans you use $vegetable_costs{Beans} .

How do you do the reverse and get the value of the key?

Anyone?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Problems Creating Temporary File

2005-07-05 Thread Dave Adams
This code should work but it does not, any suggestions? 

All I need is to create a temporary file to store some data so I can
stuff it into
another application and then trash it.  I thought it would be easy.


use utf8;
use IO::Handle;
#use File::Copy;
use File::Temp qw /tempdir tempfile /;
$dir = tempdir (CLEANUP => 1);
($fh, $filename) = tempfile( DIR => $dir);
$template = "STARrequestXX";
($fh,  $filename) = tempfile($template, DIR => $dir, SUFFIX => ".xml");
print "FILENAME: $filename\n";
#$fh->print("FILENAME: $filename\n");
$fh->print(" \n");
$fh->print(" \n");
   $fh->print(" \n");
   $fh->print(" \n");
$fh->print(" \n");
#copy($filename, "StarRequest.txt");
open (TEMPFILE , $filename) || die "Error: $!\n";
while() {
   print $_;
}
$fh->close();
#sleep(10);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Reading last 10 lines in file on Win32 Systems

2005-04-19 Thread Dave Adams
I have a 2 gig log file and I need to read only the last 10 lines.

I was also thinking something like:

1. Read in File
2. Get number of lines
3. Print last ten lines

or something like that.

DA

On 4/19/05, Wagner, David --- Senior Programmer Analyst --- WGO
<[EMAIL PROTECTED]> wrote:
> Dave Adams wrote:
> > I am new to PERL but how would I write a script that would read in a
> > file and output the last 10 lines?
> >
> > I guess it is sort of like the UNIX command of Tail.
> >
> > Any ideas,  much appreciated.
> >
> > DA
>I did a cpan search and got File::ReadBackwards .  What type of files 
> desring to read and size of said files?
> 
> Wags ;)
> 
> ***
> This message contains information that is confidential
> and proprietary to FedEx Freight or its affiliates.
> It is intended only for the recipient named and for
> the express purpose(s) described therein.
> Any other use is prohibited.
> ***
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reading last 10 lines in file on Win32 Systems

2005-04-19 Thread Dave Adams
I am new to PERL but how would I write a script that would read in a
file and output the last 10 lines?

I guess it is sort of like the UNIX command of Tail.

Any ideas,  much appreciated.

DA

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Can I do this with perl?

2002-03-04 Thread Dave Adams

Hi there,

I have a problem which I would like to use perl to resolve, however I'm not
sure if it is possible to do. 

I need to scan a file and check some conditions, first if field 9 is
duplicated on 1 or more rows, then I need to check field 10 to see which is
the greater value and then only print the whole row where field 10 is the
greater, if field 9 is not a duplicate then print the whole row.
An example of the data is below.

28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|

Dave