Urgent :search and replace

2006-06-22 Thread Preethi

Hi Experts,

I have wired problem , I have search and replace string in very huge text
file . The problem with the string is broken in the differenet line.

I'm having a  string 'ab=test1, db=test2,dc=test3' and I want to replace
this with 'ab=chk1,bc=chk2'.
This string in the file is present in various fasion like

.ab=tes
t1, db=test2,dc=test3'
, ab=
test1,db=test2,dc=test3' .
..




Now the problem when I use the below command
perl -p -i.bak -e 's/ab=test1, db=test2,dc=test3/ab=chk1,bc=chk2/gi'
filename
works only if they are in the same line. But does not replace if they are on
different lines as the exaple shown above.

Please someone could hlep me give a quick solution for this.





Thanks,
Preethi


Another (hopefully more clear) plea for help with CSV data

2006-06-22 Thread Ralph H. Stoos Jr.
All,

I have been asked to do something in Access or Excel which I find
disagreeable.  Open Source is the way to go and also, PERL is more
flexible.  I might even obtain a little professional development on this.

My last post seemed to confuse folks (thanks to all who responded).  I
will try to clarify.

Machine,PurgeSuccess,PurgePrepared,PurgeStarted,PurgeCauseFaultID,PurgeModId,PurgeStopModId,ModIdJobCfg,NameJobCfg,Full_cfg,FinisherCfg,plex,PPM,PropID,AtreeNodeID,JobID,MediaID,Width,Height,Color,Weight,Caliper,Drilled,Finish,Grain,CoatingFront,CoatingBack,SW,additional_info,debuglog
1125785731,N,Y,Y,927,6,5,_2_3_4_5_6,_SFM20_IOT7_SFM7_BFM20_BFM2,_SFM20_IOT7_SFM7_BFM20_BFM2,DUAL_BFM,Simplex,120,44366,1228,392,527,279400,431800,white,75,104,FALSE,regular,y,none,none,RV0.6.5.27,,DebugMsgLog.2006_05_24.07_48_00
1125785731,Y,Y,N,1003,6,,_2_3_4_5_6,_SFM20_IOT7_SFM7_BFM20_BFM2,_SFM20_IOT7_SFM7_BFM20_BFM2,DUAL_BFM,Duplex,120,69206,75,408,29,279400,431800,white,75,104,FALSE,regular,y,none,none,RV0.6.5.27,,DebugMsgLog.2006_05_31.14_33_25A


Above is the same slice of data.  It all lines up in neat little columns
when you drop it into a spreadsheet.  Admittedly, it could be plopped
into all sorts of database programs, but I think doing the PERL thing
will make it more flexible and easier to change.

OK, so here is the task.  The first row I want to turn into variable
names. Machine, PurgeSuccess, etc.  Then with that removed the real work
happens.  The script would then request which variables I would like to
sort on or find records (rows) that contain the "matches" specified.

As an example, of how it should work, lets say I wanted to find all
records that had a specific value in the Machine column that also
contained another specific value in the Purge Success column.  The
script would parse each row to see if there were matches in the
"record".  Iterating through the entire file (could be as many as 15000
records), the matching records (complete rows) should be written to a
new CSV file with either the name created automatically or entered by
the user.

Processing
for each row:
if Machine = "blah" AND Purge Success = "Y" and PPM = "120 etc.


The original file would be left intact for another round of parsing with
different parameters.

Hope this makes it clear.  I really would like to get this put up on one
of my Linux servers so that the developers could use it to track trends
in the data.  I would just append new data to the object file as it is
available.  TRying hard to learn PERL as my first language.  Have found
the PERL doc to be excellent and I have purchased three PERL books
hoping to be able to do this mtself and support it over time.  I even
bought two Python books to research which scripting language might
handle it better.  PERL, being the senior language, should in theory
have the most capability.  Looked at Ruby too, but don't want the RAILS
overhead.

Thanks a bunch for any help and accept my apologies for the HUGE post.

Regards,

Ralph (the total noob)

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




Re: Trying to add hyperlink

2006-06-22 Thread Muma W.

Nath, Alok (STSD) wrote:

Hi,
I was trying to add a hyperlink to each of the boxes but it was
not putting
it in the right place.Can anyone help me in this regard ?
[...]


Try this:
td([
a({href=>'http://url.example.com'}, 'My link text')
])



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




RE: Urgent :search and replace

2006-06-22 Thread Vijayakumaran, Vinod
You have 2 options:
1) Use pattern matching which would help in replacement 
s//

2) Try using split function
$w=split(//,$string to search)

3) Try using substr function
Substr($string to search, )


-Original Message-
From: Preethi [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 12:37 PM
To: beginners@perl.org
Subject: Urgent :search and replace


Hi Experts,

I have wired problem , I have search and replace string in very huge text
file . The problem with the string is broken in the differenet line.

I'm having a  string 'ab=test1, db=test2,dc=test3' and I want to replace
this with 'ab=chk1,bc=chk2'.
This string in the file is present in various fasion like

.ab=tes
t1, db=test2,dc=test3'
, ab=
test1,db=test2,dc=test3' .
..




Now the problem when I use the below command
perl -p -i.bak -e 's/ab=test1, db=test2,dc=test3/ab=chk1,bc=chk2/gi'
filename
works only if they are in the same line. But does not replace if they are on
different lines as the exaple shown above.

Please someone could hlep me give a quick solution for this.





Thanks,
Preethi


Re: Another (hopefully more clear) plea for help with CSV data

2006-06-22 Thread Dr.Ruud
"Ralph H. Stoos Jr." schreef:

> Machine,PurgeSuccess,PurgePrepared,PurgeStarted,...
> 1125785731,N,Y,Y,...
> 1125785731,Y,Y,N,
>
> Above is the same slice of data.  It all lines up in neat little
> columns when you drop it into a spreadsheet.  Admittedly, it could be
> plopped into all sorts of database programs, but I think doing the
> PERL thing will make it more flexible and easier to change.

Perl (mind the spelling) and databases work very well together.


> OK, so here is the task.  The first row I want to turn into variable
> names.

Why? I would use an array of arrays (or maybe a hash of arrays), but
only if a database was not possible.


> Machine, PurgeSuccess, etc.  Then with that removed the real
> work happens.  The script would then request which variables I would
> like to sort on or find records (rows) that contain the "matches"
> specified.

A perfect job for an RDBMS.


> As an example, of how it should work, lets say I wanted to find all
> records that had a specific value in the Machine column that also
> contained another specific value in the Purge Success column.  The
> script would parse each row to see if there were matches in the
> "record".  Iterating through the entire file (could be as many as
> 15000 records), the matching records (complete rows) should be
> written to a new CSV file with either the name created automatically
> or entered by the user.

With 15000 records the data would only be a few megabytes, so yes, it is
possible to do it in memory.


> Processing
> for each row:
> if Machine = "blah" AND Purge Success = "Y" and PPM = "120 etc.

To save memory, another way would be to access the data from file, line
by line, and test the conditions on the go.


> The original file would be left intact for another round of parsing
> with different parameters.
>
> Hope this makes it clear.  I really would like to get this put up on
> one of my Linux servers so that the developers could use it to track
> trends in the data.  I would just append new data to the object file
> as it is available.  TRying hard to learn PERL as my first language.
> Have found the PERL doc to be excellent and I have purchased three
> PERL books hoping to be able to do this mtself and support it over
> time.  I even bought two Python books to research which scripting
> language might handle it better.  PERL, being the senior language,
> should in theory have the most capability.  Looked at Ruby too, but
> don't want the RAILS overhead.

Search on CPAN for CSV:
http://search.cpan.org/search?m=module&q=CSV&s=1&n=100

Maybe this one is best for your situation:
http://search.cpan.org/~bigj/Tie-CSV_File-0.21/CSV_File.pm

Use a hash to convert colum-name to column-number.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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




RE: Trying to add hyperlink

2006-06-22 Thread Nath, Alok (STSD)
 Hi Prabhu,
Is there any simple way of doing it.Bcos this looks like user
has to type a lot.
Perl is known for its simplicity I suppose.

Thanx,
Alok.

-Original Message-
From: Prabu [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 12:06 PM
To: Nath, Alok (STSD)
Cc: beginners@perl.org
Subject: Re: Trying to add hyperlink

Hello,

Hope this is your need...

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

use CGI qw/:standard/;
print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links") ;

print table({-border=>undef,,-width=>'75%', -height=>'70%'},
caption(strong('Web Page Under construction?')),
Tr({-align=>CENTER,-valign=>TOP}, [ th(['','Network
Switch','Bay 1','Bay 2','Bay 3' ,'Network Switch' ]), th('Enclosure 1').td(['Bl20p G2','yes','yes']), th('Enclosure
2').td(['no','no','yes']) ]
)
);

end_html();


--
Prabu.M.A
When I was born I was so surprised
I didnt talk for a period and half
 -Gracie Allen

Nath, Alok (STSD) wrote:
> Hi,
>   I was trying to add a hyperlink to each of the boxes but it was
not 
> putting
>   it in the right place.Can anyone help me in this regard ?
>
> #!/usr/bin/perl -w
> use warnings ;
>
> use CGI qw/:standard/;
> print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links") ;
>
> print table({-border=>undef,,-width=>'75%', -height=>'70%'},
> caption(strong('Web Page Under construction?')),
> Tr({-align=>CENTER,-valign=>TOP},
> [
>th(['','Network Switch','Bay 1','Bay 2','Bay 3' ,'Network 
> Switch' ]),
>th('Enclosure 1').td(['Bl20p G2','yes','yes']),
>th('Enclosure 2').td(['no','no','yes']) 
> ]
>   )
> );
>
>   end_html();
>   
>
>   Also can anyone point me the links for Perl CGI tutorials with 
> emphasis on
>   handling tables and forms.
>
> Thanx,
> Alok.
>   
>
>   



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




RE: Another (hopefully more clear) plea for help with CSV data

2006-06-22 Thread Charles K. Clarkson
Ralph H. Stoos Jr. wrote:

Perl is a name, not an acronym. Write Perl or perl, but never
PERL (unless you are yelling).


: OK, so here is the task.  The first row I want to turn into
: variable names. Machine, PurgeSuccess, etc.

You probably don't want to do that. You may end up needing
symbolic references to access those variables. Using symbolic
references is frowned on. Another approach might use a hash which
has keys that match the column names. The values associated with
those keys would reference arrays of values from all the records.


: Then with that removed the real work happens.  The script would
: then request which variables I would like to sort on or find
: records (rows) that contain the "matches" specified.

Are you going to rewrite the script for each different record
search? How often will different searches be needed? Who decides
the need for new searches (you, the boss, other programmers, users,
etc.)?


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


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




Re: Trying to add hyperlink

2006-06-22 Thread Prabu

Hello Alok,

FineBut each  box needs to go to  different link right.So it 
should be specified in each box ..


If not can u a give me little more detailed requirement like on clicking 
the link in box where it should go.and so...


--
Prabu.M.A
When I was born I was so surprised
I didnt talk for a period and half
 -Gracie Allen



Nath, Alok (STSD) wrote:

 Hi Prabhu,
Is there any simple way of doing it.Bcos this looks like user
has to type a lot.
Perl is known for its simplicity I suppose.

Thanx,
Alok.

-Original Message-
From: Prabu [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 12:06 PM

To: Nath, Alok (STSD)
Cc: beginners@perl.org
Subject: Re: Trying to add hyperlink

Hello,

Hope this is your need...

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

use CGI qw/:standard/;
print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links") ;

print table({-border=>undef,,-width=>'75%', -height=>'70%'},
caption(strong('Web Page Under construction?')),
Tr({-align=>CENTER,-valign=>TOP}, [ th(['','Network
Switch','Bay 1','Bay 2','Bay 3' ,'Network Switch' ]), th('Enclosure 1').td(['Bl20p G2','yes','yes']), th('Enclosure
2').td(['no','no','yes']) ]
)
);

end_html();


--
Prabu.M.A
When I was born I was so surprised
I didnt talk for a period and half
 -Gracie Allen

Nath, Alok (STSD) wrote:
  

Hi,
I was trying to add a hyperlink to each of the boxes but it was

not 
  

putting
it in the right place.Can anyone help me in this regard ?

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

use CGI qw/:standard/;
print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links") ;

print table({-border=>undef,,-width=>'75%', -height=>'70%'},
caption(strong('Web Page Under construction?')),
Tr({-align=>CENTER,-valign=>TOP},
[
   th(['','Network Switch','Bay 1','Bay 2','Bay 3' ,'Network 
Switch' ]),

   th('Enclosure 1').td(['Bl20p G2','yes','yes']),
   th('Enclosure 2').td(['no','no','yes']) 
]

)
);

  end_html();


	Also can anyone point me the links for Perl CGI tutorials with 
emphasis on

handling tables and forms.

Thanx,
Alok.


  





  




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




RE: Trying to add hyperlink

2006-06-22 Thread Charles K. Clarkson
Prabu wrote:

: use CGI qw/:standard/;
[snip]
: th(['','Network Switch','Bay 1','Bay 2','Bay 3' ,'Network
: Switch' ]),

Sorry, that will produce invalid xhtml 1.0 Transitional, the
default DOCTYPE for CGI.pm. Better to use the a() function
already loaded into the main namespace by the 'use' statement.
It will automatically change the output should the -noxhtml
CGI.pm pragma is added later.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


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




RE: Trying to add hyperlink

2006-06-22 Thread Nath, Alok (STSD)
Hi Prabhu,
Your guess is right.For each box it should go to a different
link.
For e.g my references are like this. href="https://192.10.11.12.

I want my code to be slightly simple. 

Thanx,
Alok.

-Original Message-
From: Prabu [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 1:51 PM
To: Nath, Alok (STSD)
Cc: beginners@perl.org
Subject: Re: Trying to add hyperlink

Hello Alok,

FineBut each  box needs to go to  different link right.So it
should be specified in each box ..

If not can u a give me little more detailed requirement like on clicking
the link in box where it should go.and so...

--
Prabu.M.A
When I was born I was so surprised
I didnt talk for a period and half
 -Gracie Allen



Nath, Alok (STSD) wrote:
>  Hi Prabhu,
>   Is there any simple way of doing it.Bcos this looks like user
> has to type a lot.
>   Perl is known for its simplicity I suppose.
>
> Thanx,
> Alok.
>
> -Original Message-
> From: Prabu [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, June 22, 2006 12:06 PM
> To: Nath, Alok (STSD)
> Cc: beginners@perl.org
> Subject: Re: Trying to add hyperlink
>
> Hello,
>
> Hope this is your need...
>
> #!/usr/bin/perl -w
> use warnings ;
>
> use CGI qw/:standard/;
> print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links") ;
>
> print table({-border=>undef,,-width=>'75%', -height=>'70%'},
> caption(strong('Web Page Under construction?')),
> Tr({-align=>CENTER,-valign=>TOP}, [ th(['','Network
> Switch','Bay 1','Bay 2',' HREF="#">Bay 3' ,'Network Switch' ]), th(' HREF="#">Enclosure 1').td(['Bl20p G2',' HREF="#">yes','yes']), th('Enclosure
> 2').td(['no','no',' HREF="#">yes']) ]
> )
> );
>
> end_html();
>
>
> --
> Prabu.M.A
> When I was born I was so surprised
>   I didnt talk for a period and half
>-Gracie Allen
>
> Nath, Alok (STSD) wrote:
>   
>> Hi,
>>  I was trying to add a hyperlink to each of the boxes but it was
>> 
> not 
>   
>> putting
>>  it in the right place.Can anyone help me in this regard ?
>>
>> #!/usr/bin/perl -w
>> use warnings ;
>>
>> use CGI qw/:standard/;
>> print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links") ;
>>
>> print table({-border=>undef,,-width=>'75%', -height=>'70%'},
>> caption(strong('Web Page Under construction?')),
>> Tr({-align=>CENTER,-valign=>TOP},
>> [
>>th(['','Network Switch','Bay 1','Bay 2','Bay 3' ,'Network 
>> Switch' ]),
>>th('Enclosure 1').td(['Bl20p G2','yes','yes']),
>>th('Enclosure 2').td(['no','no','yes']) 
>> ]
>>  )
>> );
>>
>>   end_html();
>>  
>>
>>  Also can anyone point me the links for Perl CGI tutorials with 
>> emphasis on
>>  handling tables and forms.
>>
>> Thanx,
>> Alok.
>>  
>>
>>   
>> 
>
>
>
>   



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




Handle date structured folders

2006-06-22 Thread Khairul Azmi

Hi all,
I have this problem. There is a script that stores log files into folders
that follows structure of the following

/MM/DD

eg..

/var/log/projects/2006/06/20/8231.tgz
/var/log/project1/2006/06/21/1432.tgz
/var/log/projects/2006/06/22/1756.tgz
/var/log/projects/2006/06/23/1756.tgz

Now I want to write a script that would erase all logs that has been stored
except for the log for the current day. For the above example, since today
is 23 June 2006, the code will erase log files in folders 2006/06/20/ and
2006/06/21/ only. Can somebody give ideas on how to do this. This script is
to be ran once a day.

Thanks in advance.

mie


Re: Urgent :search and replace

2006-06-22 Thread Dr.Ruud
Preethi schreef:


Never put "Urgent" in the Subject. Never address "us" as Experts. Just
explain your problem.

Subject: search and replace on broken lines


> I have wired problem , I have search and replace string in very huge
> text file . The problem with the string is broken in the differenet
> line.
>
> I'm having a  string 'ab=test1, db=test2,dc=test3' and I want to
> replace this with 'ab=chk1,bc=chk2'.
> This string in the file is present in various fasion like
> 
> .ab=tes
> t1, db=test2,dc=test3'
> , ab=
> test1,db=test2,dc=test3' .
> ..

What is "very huge"? Multiple GB?

If the file is "only" a few MB, consider slurping it in:

perl -i.bak -wpe '
  { local $/;
s/a\n?
  b\n?
  =\n?
  t\n?
  e\n?
  s\n?
  t\n?
  1\n?
  ,\n?
 \ \n?
  d\n?
  b\n?
  =\n?
  t\n?
  e\n?
  s\n?
  t\n?
  2\n?
  ,\n?
  d\n?
  c\n?
  =\n?
  t\n?
  e\n?
  s\n?
  t\n?
  3\n?
  /ab=chk1,bc=chk2/xgi
  }
' filename

(untested)

The "local $/" sets the input record separator to undef. See perlvar.
The inserted \n? are optional newlines.


Your sample shows a
  ", db"
and a
  ",db"
so you'll need to adjust the regular expression above.


Handy:

perl -le '
  $s = q{ab=test1, db=test2,dc=test3} ;
  $r = join( q{\n}, split( q{}, $s ), undef) ;
  print qr/$r/
'

-- 
Affijn, Ruud

"Gewoon is een tijger."



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




Re: Urgent :search and replace

2006-06-22 Thread Preethi

Hi Ruud,

Thanks for the input. I will take care of your inputs next time I post the
message.

The below solution did not work for me . My file runs almost to 1GB . All I
have the string mentioned below.
I even tried the following option

perl -pi.bak -0777 -e 's/ab=test1, db=test2,dc=test3/ab=chk1,bc=chk2/gi'
filename.

But  it did not work. I also tried using -m. It failed.

Please let me know if there any other solution for this.

Thanks,
Preethi



On 6/22/06, Dr.Ruud <[EMAIL PROTECTED]> wrote:


Preethi schreef:


Never put "Urgent" in the Subject. Never address "us" as Experts. Just
explain your problem.

Subject: search and replace on broken lines


> I have wired problem , I have search and replace string in very huge
> text file . The problem with the string is broken in the differenet
> line.
>
> I'm having a  string 'ab=test1, db=test2,dc=test3' and I want to
> replace this with 'ab=chk1,bc=chk2'.
> This string in the file is present in various fasion like
> 
> .ab=tes
> t1, db=test2,dc=test3'
> , ab=
> test1,db=test2,dc=test3' .
> ..

What is "very huge"? Multiple GB?

If the file is "only" a few MB, consider slurping it in:

perl -i.bak -wpe '
{ local $/;
   s/a\n?
 b\n?
 =\n?
 t\n?
 e\n?
 s\n?
 t\n?
 1\n?
 ,\n?
\ \n?
 d\n?
 b\n?
 =\n?
 t\n?
 e\n?
 s\n?
 t\n?
 2\n?
 ,\n?
 d\n?
 c\n?
 =\n?
 t\n?
 e\n?
 s\n?
 t\n?
 3\n?
 /ab=chk1,bc=chk2/xgi
}
' filename

(untested)

The "local $/" sets the input record separator to undef. See perlvar.
The inserted \n? are optional newlines.


Your sample shows a
", db"
and a
",db"
so you'll need to adjust the regular expression above.


Handy:

perl -le '
$s = q{ab=test1, db=test2,dc=test3} ;
$r = join( q{\n}, split( q{}, $s ), undef) ;
print qr/$r/
'

--
Affijn, Ruud

"Gewoon is een tijger."



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





Re: Urgent :search and replace

2006-06-22 Thread Dr.Ruud
Preethi schreef:

> The below solution

... should be above, but most probably snipped.
Don't top-post, quote only relevant text, reply on each part that you
quote.


> did not work for me. My file runs almost to 1GB.

What was the error message?


Also show us the output of this:

perl -wne '
   $x ||= 0; $x = length if $x < length }
 { print "Lines: $.\n", "Max.len: $x\n"
' filename



> All I have the string mentioned below.
> I even tried the following option
>
> perl -pi.bak -0777 -e 's/ab=test1,
> db=test2,dc=test3/ab=chk1,bc=chk2/gi' filename.
>
> But  it did not work. I also tried using -m. It failed.

Such trial-and-error will get you nowhere.

The -0777 "works" the same as the "local $/", see:
$ perl -MO=Deparse -0777 -e ''
BEGIN { $/ = undef; $\ = undef; }


perlrun says:
-m module executes "use" module "();" before executing
   your program.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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




RE: Urgent :search and replace

2006-06-22 Thread Nagasamudram, Prasanna Kumar
Hi Preethi

Can you try...

perl -pi.bak -e 's/(ab=test1.*?dc=test3)/ab=chk1,bc=chk2/sg' filename


[untested]

Thanks
Prasanna

-Original Message-
From: Preethi [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 3:21 PM
To: Dr.Ruud
Cc: beginners@perl.org
Subject: Re: Urgent :search and replace

Hi Ruud,

Thanks for the input. I will take care of your inputs next time I post
the
message.

The below solution did not work for me . My file runs almost to 1GB .
All I
have the string mentioned below.
I even tried the following option

perl -pi.bak -0777 -e 's/ab=test1, db=test2,dc=test3/ab=chk1,bc=chk2/gi'
filename.

But  it did not work. I also tried using -m. It failed.

Please let me know if there any other solution for this.

Thanks,
Preethi



On 6/22/06, Dr.Ruud <[EMAIL PROTECTED]> wrote:
>
> Preethi schreef:
>
>
> Never put "Urgent" in the Subject. Never address "us" as Experts. Just
> explain your problem.
>
> Subject: search and replace on broken lines
>
>
> > I have wired problem , I have search and replace string in very huge
> > text file . The problem with the string is broken in the differenet
> > line.
> >
> > I'm having a  string 'ab=test1, db=test2,dc=test3' and I want to
> > replace this with 'ab=chk1,bc=chk2'.
> > This string in the file is present in various fasion like
> > 
> > .ab=tes
> > t1, db=test2,dc=test3'
> > , ab=
> > test1,db=test2,dc=test3' .
> > ..
>
> What is "very huge"? Multiple GB?
>
> If the file is "only" a few MB, consider slurping it in:
>
> perl -i.bak -wpe '
> { local $/;
>s/a\n?
>  b\n?
>  =\n?
>  t\n?
>  e\n?
>  s\n?
>  t\n?
>  1\n?
>  ,\n?
> \ \n?
>  d\n?
>  b\n?
>  =\n?
>  t\n?
>  e\n?
>  s\n?
>  t\n?
>  2\n?
>  ,\n?
>  d\n?
>  c\n?
>  =\n?
>  t\n?
>  e\n?
>  s\n?
>  t\n?
>  3\n?
>  /ab=chk1,bc=chk2/xgi
> }
> ' filename
>
> (untested)
>
> The "local $/" sets the input record separator to undef. See perlvar.
> The inserted \n? are optional newlines.
>
>
> Your sample shows a
> ", db"
> and a
> ",db"
> so you'll need to adjust the regular expression above.
>
>
> Handy:
>
> perl -le '
> $s = q{ab=test1, db=test2,dc=test3} ;
> $r = join( q{\n}, split( q{}, $s ), undef) ;
> print qr/$r/
> '
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."
>
>
>
> --
> 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]
 




Re: Storing an array in a hash

2006-06-22 Thread Mr. Shawn H. Corey
On Thu, 2006-22-06 at 01:47 +, Jeff Peng wrote:
> > > This conversion to and fro must be inefficient and time consuming.  Is
> > > there a "better" way to do this?
> >
> >Use an anonymous array:
> >
> >   $array{$client} = [ @field ];
> >
> >   @field = @{ $array{$client} };
> >
> >
> 
> Or use the array's reference as the hash's values:
> 
> $array{$client} = [EMAIL PROTECTED];

This will not save the contents of @field, it only saves a reference to
it:

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

my @field = qw( a b c );
my $save = [EMAIL PROTECTED];
print Dumper $save;

@field = qw( 1 2 3 );
print Dumper $save;

__END__

An alternate notation is:

  @{ $array{$client} } = @field;


-- 
__END__

Just my 0.0002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



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




Re: Handle date structured folders

2006-06-22 Thread Mr. Shawn H. Corey
On Thu, 2006-22-06 at 16:45 +0800, Khairul Azmi wrote:
> Hi all,
> I have this problem. There is a script that stores log files into folders
> that follows structure of the following
> 
> /MM/DD
> 
> eg..
> 
> /var/log/projects/2006/06/20/8231.tgz
> /var/log/project1/2006/06/21/1432.tgz
> /var/log/projects/2006/06/22/1756.tgz
> /var/log/projects/2006/06/23/1756.tgz
> 
> Now I want to write a script that would erase all logs that has been stored
> except for the log for the current day. For the above example, since today
> is 23 June 2006, the code will erase log files in folders 2006/06/20/ and
> 2006/06/21/ only. Can somebody give ideas on how to do this. This script is
> to be ran once a day.
> 
> Thanks in advance.
> 
> mie

The module File::Find comes with Perl. See `perldoc File::Find` for
details.

-- 
__END__

Just my 0.0002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



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




converting between time and string

2006-06-22 Thread bnj.s

Hello,

I have a file with lots of times in the format "01:22:33,456", where the 
numbers after the comma represent the milliseconds.


I would like to reduce all these times by a given offset. I first 
thought to convert the string to a sort of date format, and then to do a 
minus operation, and then to convert the result back to a string of the 
original form. However, I have great difficulties finding how to handle 
times and dates. I am sure, however, that there exist a simple way to do 
so in perl. Could you please help me and tell me how you would do it?


Thank you and best regards,

Benjamin

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




Serial Ports

2006-06-22 Thread Scott Taylor

Hello all,

I have a robot that sends data over a serial connection and I'd like to
use Perl/Linux to listen to the Serial Port and record the data.  Can
anyone suggest the best package to do this?  I need to be able to set Baud
rates and such too.  I'm looking at Device::SerialPort, but is that the
best way to go about this?

Thanks.

--
Scott


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




Re: Trying to add hyperlink

2006-06-22 Thread chen li


--- Prabu <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> Hope this is your need...
> 
> #!/usr/bin/perl -w
> use warnings ;
> 
> use CGI qw/:standard/;
> print header, start_html("Stsd ILO Links"), h1("Stsd
> ILO Links") ;
> 
> print table({-border=>undef,,-width=>'75%',
> -height=>'70%'},
> caption(strong('Web Page Under construction?')),
> Tr({-align=>CENTER,-valign=>TOP},
> [
> th(['','Network Switch',' HREF="#">Bay 1',' HREF="#">Bay 2','Bay 3' ,' HREF="#">Network
> Switch' ]),
> th('Enclosure 1').td([' HREF="#">Bl20p G2',' HREF="#">yes','yes']),
> th('Enclosure 2').td([' HREF="#">no',' HREF="#">no','yes'])
> ]
> )
> );
> 
> end_html();

Hi all,

How to convert the format above into an OOP style when
adding a hyperlink? I am afraid  many people might
have typo if they follow the format above.

Thank you,


Li

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




Re: Trying to add hyperlink

2006-06-22 Thread Scott Taylor

On Thu, June 22, 2006 09:25, chen li wrote:
>
>
> --- Prabu <[EMAIL PROTECTED]> wrote:
>
>> Hello,
>>
>> Hope this is your need...
>>
>> #!/usr/bin/perl -w
>> use warnings ;
>>
>> use CGI qw/:standard/;
>> print header, start_html("Stsd ILO Links"), h1("Stsd
>> ILO Links") ;
>>
>> print table({-border=>undef,,-width=>'75%',
>> -height=>'70%'},
>> caption(strong('Web Page Under construction?')),
>> Tr({-align=>CENTER,-valign=>TOP},
>> [
>> th(['','Network Switch','> HREF="#">Bay 1','> HREF="#">Bay 2','Bay 3' ,'> HREF="#">Network
>> Switch' ]),
>> th('Enclosure 1').td(['> HREF="#">Bl20p G2','> HREF="#">yes','yes']),
>> th('Enclosure 2').td(['> HREF="#">no','> HREF="#">no','yes'])
>> ]
>> )
>> );
>>
>> end_html();
>
> Hi all,
>
> How to convert the format above into an OOP style when
> adding a hyperlink? I am afraid  many people might
> have typo if they follow the format above.

THis might help:
http://search.cpan.org/src/LDS/CGI.pm-3.08/cgi_docs.html

--
Scott


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




RE: Trying to add hyperlink

2006-06-22 Thread Charles K. Clarkson
chen li wrote:

: How to convert the format above into an OOP style when
: adding a hyperlink? I am afraid  many people might
: have typo if they follow the format above.


First, let's fix a few things with this implementation. Use
the -w or the warnings pragma, not both. The preference is for
the pragma. Read pererllexwarn in the docs for details. Always
use strict.

: #!/usr/bin/perl -w
: use warnings;

#!/usr/bin/perl

use strict;
use warnings;


: use CGI qw/:standard/;
: print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links");
:
: print table({-border=>undef,,-width=>'75%', -height=>'70%'},

Under xhtml there is no height attribute for tables, you are
required to present a summary and 'border' cannot be undef under
CGI.pm. You also have an extra comma up there, though I don't
think it hurts anything.

print
header(),
start_html( 'Stsd ILO Links' ),
h1( 'Stsd ILO Links' ),
table(
{
-border  => 0,
-width   => '75%',
-summary => 'Table of Enclosure features',
},

: caption(strong('Web Page Under construction?')),
: Tr({-align=>CENTER,-valign=>TOP},

Under 'use strict', CENTER and TOP are illegal barewords. Put
them in quotes. Valid xhtml requires 'center' and 'top' (no
capitilization).

Tr(
{
-align  => 'center',
-valign => 'top'
},


: [
:th(['','Network Switch','Bay 1','Bay 2','Bay 3' ,'Network
Switch' ]),
:th('Enclosure 1').td(['Bl20p G2','yes','yes']),
:th('Enclosure 2').td(['no','no','yes'])


th( 'Enclosure 1' ) .
td(
[
a( { -href => '/' }, 'Bl20p G2' ),
a( { -href => '/' }, 'yes' ),
a( { -href => '/' }, 'yes' ),
]
),

th( 'Enclosure 2' ) .
td(
[
a( { -href => '/' }, 'no' ),
a( { -href => '/' }, 'no' ),
a( { -href => '/' }, 'yes' ),
]
),


: ]
:   )
: );

Use a comma here instead of a semicolon or add a print
statement to the next line. As Prabu already mentioned, you need to
add an anchor to each box you want to link from. There's no easy
way around it.

We could use a subroutines to eliminated some typing.

use strict;
use warnings;

use CGI qw/:standard/;
print
header(),
start_html( 'Stsd ILO Links' ),
h1( 'Stsd ILO Links' ),
table(
{
-border  => 0,
-width   => '75%',
-summary => 'Table of Enclosure features',
},
caption( strong( 'Web Page Under construction?' ) ),
Tr(
{
-align  => 'center',
-valign => 'top'
},
[
th(
[
'',
'Network Switch',
'Bay 1',
'Bay 2',
'Bay 3',
'Network Switch'
]
),

row(
'Enclosure 1',
'/' => 'Bl20p G2',
'/' => 'yes',
'/' => 'yes',
),

row(
'Enclosure 2',
'/' => 'no',
'/' => 'no',
'/' => 'yes',
),
]
)
),
end_html();

sub row {
my $name = shift;
return
th( 'Enclosure 2' ) .
td( anchors( @_ ) );
}

sub anchors {
my @anchors = @_;

my @return;
while ( @anchors ) {
push @return, a( { -href => shift @anchors }, shift @anchors ),
}

return [EMAIL PROTECTED];
}

__END__


In OO style.

use strict;
use warnings;

use CGI;
my $q = CGI->new();

print
$q->header(),
$q->start_html( 'Stsd ILO Links' ),
$q->h1( 'Stsd ILO Links' ),
$q->table(
{
-border  => 0,
-width   => '75%',
-summary => 'Table of Enclosure features',
},
$q->caption(
$q->strong( 'Web Page Under construction?' )
),
$q->Tr(
{
-align  => 'center',
-valign => 'top'
},
[
$q->th(
[
'',
'Network Switch',
  

Re: Another (hopefully more clear) plea for help with CSV data

2006-06-22 Thread Chad Perrin
On Thu, Jun 22, 2006 at 03:07:32AM -0500, Charles K. Clarkson wrote:
> 
> : OK, so here is the task.  The first row I want to turn into
> : variable names. Machine, PurgeSuccess, etc.
> 
> You probably don't want to do that. You may end up needing
> symbolic references to access those variables. Using symbolic
> references is frowned on. Another approach might use a hash which
> has keys that match the column names. The values associated with
> those keys would reference arrays of values from all the records.

I must be missing something.  Please explain the sentence "You may end
up needing symbolic references to access those variables."


> 
> : Then with that removed the real work happens.  The script would
> : then request which variables I would like to sort on or find
> : records (rows) that contain the "matches" specified.
> 
> Are you going to rewrite the script for each different record
> search? How often will different searches be needed? Who decides
> the need for new searches (you, the boss, other programmers, users,
> etc.)?

Why would he need to rewrite the script?  Why couldn't it just loop
through input data to (for instance) create an array containing each
row, starting with the column headings row, then shift from each array
to name new arrays from the column headings row and populate it in order
from the other rows?  I'm not saying that's necessarily the best way to
do it, but it seems like a reasonable example of how the script could
just dynamically handle different data from each run if need be without
having to rewrite it each time.  Some search functions could be created
that simply take input that allows for search terms to be specified when
the script is run.  Voila, it works.  Did I misunderstand your point?

Of course, this seems like a lot of unnecessary work, since it basically
involves writing one's own simple DBMS query system, but it would seem
to suit the OP's requirements.

-- 
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"The measure on a man's real character is what he would do
if he knew he would never be found out." - Thomas McCauley

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




Re: converting between time and string

2006-06-22 Thread Muma W.

bnj.s wrote:

Hello,

I have a file with lots of times in the format "01:22:33,456", where the 
numbers after the comma represent the milliseconds.


I would like to reduce all these times by a given offset. [...]


You can use POSIX::mktime to convert the string into a time value, but 
the milliseconds must be left out.




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




Re: Handle date structured folders

2006-06-22 Thread Chad Perrin
On Thu, Jun 22, 2006 at 04:45:25PM +0800, Khairul Azmi wrote:
> Hi all,
> I have this problem. There is a script that stores log files into folders
> that follows structure of the following
> 
> /MM/DD
> 
> eg..
> 
> /var/log/projects/2006/06/20/8231.tgz
> /var/log/project1/2006/06/21/1432.tgz
> /var/log/projects/2006/06/22/1756.tgz
> /var/log/projects/2006/06/23/1756.tgz
> 
> Now I want to write a script that would erase all logs that has been stored
> except for the log for the current day. For the above example, since today
> is 23 June 2006, the code will erase log files in folders 2006/06/20/ and
> 2006/06/21/ only. Can somebody give ideas on how to do this. This script is
> to be ran once a day.

If it's run every day, you could conceivably decrement the date by one
every day and delete the file corresponding with the date you get by
decrementing.  This isn't a very fault tolerant solution, but it's a
simple one.  The first time you run it, you'll have to delete anything
before the current date, of course.

To delete all previous dates, in case you end up with more than one, you
could use a for loop or similar increment/decrement looping structure to
delete files starting with a first decremented date and stop when you
can't find a file that matches a decremented date value.

You may want to search CPAN for a date-handling module that suits your
purposes so you don't have to write all the date-handling logic of your
program yourself.  You've already received a suggestion of what to use
for handling file operations in another reply to your request.

Whatever you do, I recommend of course that you use the strict and
warnings pragmas, and test the heck out of it on sample files before
using it on the real things if you care about whether you lose your
data during testing.

-- 
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Ben Franklin: "As we enjoy great Advantages from the Inventions of
others we should be glad of an Opportunity to serve others by any
Invention of ours, and this we should do freely and generously."

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




Error connecting to 'http://ppm.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer'

2006-06-22 Thread Ley, Chung
Hi,

 

I am trying to use PPM to install some module, I am running version
2.2.0.  But I got this error...  Is there something happening on the
server side or is this some thing that I need to check with my network?
Is this has to do with ActiveState spinning out?

 

I am sorry, I didn't know who to contact on this...

 

Thanks...

 

--Chung



Re: converting between time and string

2006-06-22 Thread Dr.Ruud
"bnj.s" schreef:

> I have a file with lots of times in the format "01:22:33,456", where
> the numbers after the comma represent the milliseconds.
>
> I would like to reduce all these times by a given offset. I first
> thought to convert the string to a sort of date format, and then to
> do a minus operation, and then to convert the result back to a string
> of the original form. However, I have great difficulties finding how
> to handle times and dates. I am sure, however, that there exist a
> simple way to do so in perl. Could you please help me and tell me how
> you would do it?


What is the smallest (earliest) time value, and is it bigger than the
offset?

If yes:

#!/usr/bin/perl
  use strict ;
  use warnings ;

  use integer ;

  sub t2ms
  {
$_[3] ||= '' ;
$_[3]  .= '0' while length $_[3] < 3 ;
return ( ( $_[0] * 60 + $_[1] ) * 60 + $_[2] ) * 1000 + $_[3] ;
  }

  sub ms2t
  {
$_[3] = $_[0] % (  1000);
$_[2] = $_[0] % ( 60 * 1000) / (  1000) ;
$_[1] = $_[0] % (60 * 60 * 1000) / ( 60 * 1000) ;
$_[0] = $_[0]/ (60 * 60 * 1000) ;
return @_ ;
  }

  my $qr = qr/(\d\d):(\d\d):(\d\d)(?:,(\d*))?/ ;

  my $offset = - t2ms( '00:00:01,234' =~ m/$qr/ ) ;

  while (  )
  {
printf "%02d:%02d:%02d,%03d\n", ms2t( t2ms( m/$qr/ ) + $offset ) ;
  }

__DATA__
01:22:33,456
12:34:56,7
23:45:19,001
23:45:19,01
23:45:19,0
23:45:19,
23:45:19


But please check out DateTime::Duration too.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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




Re: Handle date structured folders

2006-06-22 Thread John Ackley



Khairul Azmi wrote:

Hi all,
I have this problem. There is a script that stores log files into folders
that follows structure of the following

/MM/DD

eg..

/var/log/projects/2006/06/20/8231.tgz
/var/log/project1/2006/06/21/1432.tgz
/var/log/projects/2006/06/22/1756.tgz
/var/log/projects/2006/06/23/1756.tgz

Now I want to write a script that would erase all logs that has been 
stored
except for the log for the current day. For the above example, since 
today

is 23 June 2006, the code will erase log files in folders 2006/06/20/ and
2006/06/21/ only. Can somebody give ideas on how to do this. This 
script is

to be ran once a day.

Thanks in advance.

mie


assuming, as you state, "erase log files" (not directories)
assuming 2 days prior as per your example
assuming all earlier log files
try this which is easy to modify if assumptions are not correct


#! /usr/bin/perl

use strict;
use warnings;

use Date::Manip;

my $directory;
my $days = 2;
while( -d
   ($directory =
   UnixDate(DateCalc('today',"$days ago"),
   '/var/log/projects/%Y/%m/%d')) ) {
   unlink "$directory/*";
   $days++;
}

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




Re: Handle date structured folders - CORRECTIO

2006-06-22 Thread John Ackley

argument 2 of DateCalc() should be "$days days ago" NOT "$days ago"
sorry

John Ackley wrote:



Khairul Azmi wrote:

Hi all,
I have this problem. There is a script that stores log files into 
folders

that follows structure of the following

/MM/DD

eg..

/var/log/projects/2006/06/20/8231.tgz
/var/log/project1/2006/06/21/1432.tgz
/var/log/projects/2006/06/22/1756.tgz
/var/log/projects/2006/06/23/1756.tgz

Now I want to write a script that would erase all logs that has been 
stored
except for the log for the current day. For the above example, since 
today
is 23 June 2006, the code will erase log files in folders 2006/06/20/ 
and
2006/06/21/ only. Can somebody give ideas on how to do this. This 
script is

to be ran once a day.

Thanks in advance.

mie


assuming, as you state, "erase log files" (not directories)
assuming 2 days prior as per your example
assuming all earlier log files
try this which is easy to modify if assumptions are not correct


#! /usr/bin/perl

use strict;
use warnings;

use Date::Manip;

my $directory;
my $days = 2;
while( -d
   ($directory =
   UnixDate(DateCalc('today',"$days ago"),
   '/var/log/projects/%Y/%m/%d')) ) {
   unlink "$directory/*";
   $days++;
}



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




Re: converting between time and string

2006-06-22 Thread Mark Harris

bnj.s wrote:

Hello,

I have a file with lots of times in the format "01:22:33,456", where the 
numbers after the comma represent the milliseconds.


I would like to reduce all these times by a given offset. I first 
thought to convert the string to a sort of date format, and then to do a 
minus operation, and then to convert the result back to a string of the 
original form. However, I have great difficulties finding how to handle 
times and dates. I am sure, however, that there exist a simple way to do 
so in perl. Could you please help me and tell me how you would do it?


Thank you and best regards,

Benjamin


Unless I don't quite get what you're asking this seems pretty simple
# string to milliseconds
$refTime = "01:22:33,456"; #as in your example
$refTime =~ /(\d+):(\d+):(\d+),(\d+)/; #capture the elements and assign
$hours = $1;
$minutes = $2;
$secs = $3;
$mili = $4;

#calc milliseconds if needed

$millisec = $mili+($secs*1000)+($minutes*60*1000)+($hours*60*60*1000);
#reduce minutes by 5
$minutes-= 5;
#format for printing
$outStr = sprintf("%02d:%02d:%02d,%03d",$hours,$minutes,$secs,$mili);
print $outStr;

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




RE: Another (hopefully more clear) plea for help with CSV data

2006-06-22 Thread Timothy Johnson
Here's one thought:

Why not create a hash of arrays?  Each hash key would be a column name,
and each record would be spread across the arrays using the same array
index.  If you really wanted to get fancy you could create a hash of
cached results to speed up future queries. I wouldn't recommend it over
using an RDBMS or even Excel, but as an exercise it can be done.  

As a side note, all religious convictions about Open Source aside, using
DBI and Access would be a decent solution to a problem like this, since
it sounds like you already own it.  If you wanted to use Linux
exclusively, though there are plenty of other options available to you,
like MySQL.  




-Original Message-
From: Ralph H. Stoos Jr. [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 21, 2006 9:34 PM
To: beginners@perl.org
Subject: Another (hopefully more clear) plea for help with CSV data

All,

I have been asked to do something in Access or Excel which I find
disagreeable.  Open Source is the way to go and also, PERL is more
flexible.  I might even obtain a little professional development on
this.

My last post seemed to confuse folks (thanks to all who responded).  I
will try to clarify.

Machine,PurgeSuccess,PurgePrepared,PurgeStarted,PurgeCauseFaultID,PurgeM
odId,PurgeStopModId,ModIdJobCfg,NameJobCfg,Full_cfg,FinisherCfg,plex,PPM
,PropID,AtreeNodeID,JobID,MediaID,Width,Height,Color,Weight,Caliper,Dril
led,Finish,Grain,CoatingFront,CoatingBack,SW,additional_info,debuglog
1125785731,N,Y,Y,927,6,5,_2_3_4_5_6,_SFM20_IOT7_SFM7_BFM20_BFM2,_SFM20_I
OT7_SFM7_BFM20_BFM2,DUAL_BFM,Simplex,120,44366,1228,392,527,279400,43180
0,white,75,104,FALSE,regular,y,none,none,RV0.6.5.27,,DebugMsgLog.2006_05
_24.07_48_00
1125785731,Y,Y,N,1003,6,,_2_3_4_5_6,_SFM20_IOT7_SFM7_BFM20_BFM2,_SFM20_I
OT7_SFM7_BFM20_BFM2,DUAL_BFM,Duplex,120,69206,75,408,29,279400,431800,wh
ite,75,104,FALSE,regular,y,none,none,RV0.6.5.27,,DebugMsgLog.2006_05_31.
14_33_25A


long explanation of searchable records problem



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




Re: converting between time and string

2006-06-22 Thread JupiterHost.Net

Hello,


$refTime = "01:22:33,456"; #as in your example
$refTime =~ /(\d+):(\d+):(\d+),(\d+)/; #capture the elements and assign
$hours = $1;
$minutes = $2;
$secs = $3;
$mili = $4;


or much simpler:

my($hours, $minutes, $secs, $mili) = $ref_time =~ m{(\d+)}g;

Note that if it doesn't match then the variable will be undef...

This doesn't look strict or wanrings safe either, please always use

 use strict;
 use warnings;

Please buy Perl best Practices, you'll love it and your code will be 
much more readable (like $ref_time vs $refTime is clearer and less 
problem prone...)


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




RE: Another (hopefully more clear) plea for help with CSV data

2006-06-22 Thread Charles K. Clarkson
Chad Perrin wrote:

: On Thu, Jun 22, 2006 at 03:07:32AM -0500, Charles K. Clarkson wrote:
::
::: OK, so here is the task.  The first row I want to turn into
::: variable names. Machine, PurgeSuccess, etc.
::
:: You probably don't want to do that. You may end up needing
:: symbolic references to access those variables. Using symbolic
:: references is frowned on. Another approach might use a hash which
:: has keys that match the column names. The values associated with
:: those keys would reference arrays of values from all the records.
:
: I must be missing something.  Please explain the sentence "You
: may end up needing symbolic references to access those variables."


Ralph wants to create variables named as columns. Since each
variable will hold an array, he will probably go with these.

@Machine,
@PurgeSuccess,
@PurgePrepared,
@PurgeStarted,
@PurgeCauseFaultID,
@PurgeModId,
@PurgeStopModId,
@ModIdJobCfg,
@NameJobCfg,
@Full_cfg,
@FinisherCfg,
@plex,
@PPM,
@PropID,
@AtreeNodeID,
@JobID,
@MediaID,
@Width,
@Height,
@Color, and
@Weight

Assume Ralph writes a generic program which allows the user to
define searches using column names. Problem: How do we use the
variable with only the column name? Assuming the column name is in
variable named $column_name, this comes to mind. Note that
@ModIdJobCfg cannot be lexically scoped. Neither can the other 20
variables above.

# For testing. Normally comes from user.
my $column_name = 'ModIdJobCfg';

# For testing. This data would normally come from a file.
our @ModIdJobCfg = 1 .. 3;

{
no strict 'refs';

print "$_\n" foreach @{ $column_name };
}


If we used a hash of arrays, we would be able to avoid
symbolic references. Note that we can also test for column name
availability easier with the hash as well.

# For testing. Normally comes from user.
my $column_name = 'ModIdJobCfg';

# For testing. This data would normally come from a file and
# contain more keys.
my %jobs = (
ModIdJobCfg => [ 1 .. 3 ],
);

print  "$_\n" foreach @{ $jobs{ $column_name } };



: : Are you going to rewrite the script for each different
: : record search? How often will different searches be needed?
: : Who decides the need for new searches (you, the boss, other
: : programmers, users, etc.)?
:
: Why would he need to rewrite the script?

To do a significantly different search. If he's not rewriting
the script than he is creating his own query lanqage.


: Why couldn't it just loop through input data to (for instance)
: create an array containing each row, starting with the column
: headings row, then shift from each array to name new arrays from
: the column headings row and populate it in order from the other
: rows?

I was asking questions, not making statements. If the searches
are going to change regularly and if non perl programmers are
going to do the searches, then Ralph is basically creating his
own SQL language and a database may be a better solution. If only
perl programmers are going to do the searches then they can just
rewrite the script each time they do new search. I don't know what
Ralph needs, hence the reason for my questions.


: I'm not saying that's necessarily the best way to do it, but it
: seems like a reasonable example of how the script could just
: dynamically handle different data from each run if need be
: without having to rewrite it each time.  Some search functions
: could be created that simply take input that allows for search
: terms to be specified when the script is run.  Voila, it works.
: Did I misunderstand your point?

I wasn't making a point. I was asking for more information.
That's why all the sentences had question marks at the end.

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


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




should be a seamless upgrade?

2006-06-22 Thread tom arnall
  There's a new CPAN.pm version (v1.87) available!
  [Current version is v1.7601]
  You might want to try
install Bundle::CPAN
reload cpan
  without quitting the current session. It should be a seamless upgrade
  WHILE WE ARE RUNNING...

do not the cap'd words mean that i can continue doing the install/whatever 
which i originally came to do? 'install Bundle::CPAN' however ties the 
utility up until the cpan install is done.

Tom Arnall
north spit, ca






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




Re: should be a seamless upgrade?

2006-06-22 Thread Tom Phoenix

On 6/22/06, tom arnall <[EMAIL PROTECTED]> wrote:


  without quitting the current session. It should be a seamless upgrade
  WHILE WE ARE RUNNING...


That means that you don't need to restart the CPAN shell to benefit
from the upgrade. You do, however, have to download, build, test, and
install the upgrade before you can benefit from it; and all that can
take some time. There's no way to install anything else while that's
happening, either, which is probably a good thing to avoid tricky
concurrency issues. The bugfixes and occasional new features of an
upgrade are generally worth the effort, but feel free to postpone any
upgrade until you need to apply it.

...or even a moment earlier. Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




'-d' with '>' creates errors

2006-06-22 Thread tom arnall

invoking a perl script with '#!/usr/perl -wd' in its first line and 
with  './myscript >t' on the command line, i get as below. i have done this 
kind of thing many times, but never with this result. also, the script runs 
fine if i drop '>t' from the invocation, or drop '-d' from the first line of 
the script.


$ ./myscript >t

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(./myscript:12):  ;
Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and 
LINES environment variables didn't work. The resize program didn't work. 
at /usr/lib/perl5/Term/ReadKey.pm line 343.
Compilation failed in require at /usr/share/perl5/Term/ReadLine/Perl.pm line 
58.
 at /usr/share/perl5/Term/ReadLine/Perl.pm line 58

Term::ReadLine::Perl::new('Term::ReadLine', 'perldb', 'GLOB(0x823a250)', 
'GLOB(0x81e5a8c)') 
called at /usr/share/perl/5.8/perl5db.pl line 6029
DB::setterm called at /usr/share/perl/5.8/perl5db.pl line 2203
DB::DB called at ./myscript line 12
Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
  DB<1>
=

thanks,

tom arnall
north spit, ca






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




Re: '-d' with '>' creates errors

2006-06-22 Thread Tom Phoenix

On 6/22/06, tom arnall <[EMAIL PROTECTED]> wrote:


invoking a perl script with '#!/usr/perl -wd' in its first line and
with  './myscript >t' on the command line,


What are you trying to do? The output redirection is confusing to the
debugger. If you're trying to make a transcript of your debugger
session, there's probably a better way to do that. If you're trying
debug a program and send its default output to a file, you can do that
from within the program, for example in a BEGIN block:

 open DEBUG_OUT, ">./t" or die "Can't open file 't' for output: $!";
 select DEBUG_OUT;  # now the default for print and printf

Alternatively, you should even be able to do the same thing from
within the debugger, by typing those two lines into the debugger as
the first two commands before the rest of your program starts running.

Does that work for you? Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




Re: reading a line at a time inefficient?

2006-06-22 Thread Omega -1911

Hello list!

I am attempting to lower the memory load on the server that the following
lines of code creates. Is there any way to speed up this process and lower
memory usage? I read through FILE::SLURP documentation but not sure if that
would help as I need to keep the array @remaining_file_lines.

NOTE: Each file has a different size (ranging from 2kb up to 900mb)

open FILE, "$file.txt"; #  $file is untainted by code before we open the
file
my ($data,$data1,$data2,$data3,$data4,@remaining_file_lines) = ;
   close FILE; chomp
($data,$data1,$data2,$data3,$data4,@remaining_file_lines);
   return ($data,$data1,$data2,$data3,$data4,@remaining_file_lines);

TIA 
-David


Re: reading a line at a time inefficient?

2006-06-22 Thread Jeff Peng

Hello,
Reading a file which is large as 900M to the array,should consume memory too 
quickly.
Could you open a file and obtain the file-handle in your subroutine,then 
return the file-handle to the caller?For example:


sub your_sub{
   
   open (FH,$somefile) or die $!;
   return \*FH;
}



From: "Omega -1911" <[EMAIL PROTECTED]>
To: "Beginners Perl" 
Subject: Re: reading a line at a time inefficient?
Date: Fri, 23 Jun 2006 02:14:52 -0400

Hello list!

I am attempting to lower the memory load on the server that the following
lines of code creates. Is there any way to speed up this process and lower
memory usage? I read through FILE::SLURP documentation but not sure if that
would help as I need to keep the array @remaining_file_lines.

NOTE: Each file has a different size (ranging from 2kb up to 900mb)

open FILE, "$file.txt"; #  $file is untainted by code before we open the
file
my ($data,$data1,$data2,$data3,$data4,@remaining_file_lines) = ;
   close FILE; chomp
($data,$data1,$data2,$data3,$data4,@remaining_file_lines);
   return ($data,$data1,$data2,$data3,$data4,@remaining_file_lines);

TIA 
-David




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




Re: reading a line at a time inefficient?

2006-06-22 Thread Omega -1911

On 6/23/06, Jeff Peng <[EMAIL PROTECTED]> wrote:


Hello,
Reading a file which is large as 900M to the array,should consume memory
too
quickly.
Could you open a file and obtain the file-handle in your subroutine,then
return the file-handle to the caller?For example:

sub your_sub{

open (FH,$somefile) or die $!;
return \*FH;
}



Thanks for the reply Jeff, but what I need to do is assign variables based
on the first 5 lines and then push the remaining lines of the file into an
array. Any suggestions?

Maybe I am asking this incorrectly. Here is what I am attempting to do:

-Open one file.
-Read that file.
--Line one will be assigned to $data1
--Line two will be " " to $data2
..
--Line five will be " " to $data5
-- The remaining lines pushed into an array...

Really appreciate any help you can give!

-David


Re: reading a line at a time inefficient?

2006-06-22 Thread Jeff Peng



Thanks for the reply Jeff, but what I need to do is assign variables based
on the first 5 lines and then push the remaining lines of the file into an
array. Any suggestions?



Anyway,reading all the contents of a large file to an array should consume 
too much physical memory.Could you take a look at Tile::File module?see 
here:

http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm



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




Re: reading a line at a time inefficient?

2006-06-22 Thread Omega -1911

On 6/23/06, Jeff Peng <[EMAIL PROTECTED]> wrote:



>Thanks for the reply Jeff, but what I need to do is assign variables
based
>on the first 5 lines and then push the remaining lines of the file into
an
>array. Any suggestions?
>

Anyway,reading all the contents of a large file to an array should consume
too much physical memory.Could you take a look at Tile::File module?see
here:
http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm


Thanks Jeff, will give it a try