Perl oneliner to delete lines from a file

2004-08-08 Thread Ramprasad A Padmanabhan
I want to write a command line perl 'script'  to delete one or more 
lines from a file , by line number


for eg in sed I can do the same in two steps 
 
  cat FILENAME | sed -e '1,10d' >FILENAME.TMP
  mv FILENAME.TMP FILENAME

The above mechanism has a  lot of pitfalls , like maintaining
permissions , making sure FILENAME.TMP  does not already exist etc.
That is why I want to do it with "perl -i " 
but I dont want to write a full script for this , because  I am going to
run it on remote machines ( automated ) , and I cant ftp the script
everywhere

Any suggestions
Thanks
Ram 



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




Re: Creating hash with multiple keys for an array

2004-08-08 Thread Edward WIJAYA

What have you done to find out?
 perldoc -f sort
 perldoc -q "sort an array"
I think you also need to read up on data structures:
 perldoc perldsc
Gunnar,
It works!
I can't express enough my gratitude for your
help and patience.
I apologize for having trouble you this far.
Actually I did some reading on array sorting.
However, I admit I didn't do enough reading especially
on the topic of "hash reference".
Gratefuly yours,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Assignment for Perl Class- hurting my brain

2004-08-08 Thread James Edward Gray II
On Aug 8, 2004, at 2:24 AM, William Paoli wrote:
Im not looking to cheat, just a push in the right
direction.
It's hard form me to help you much, without showing code.  And of 
course, if I use something you're teacher hasn't taught yet...

Still, I'll try to give a hint or two.
[snip]
The field format of the file is structured like this:
"Car Number":"Driver Name":"Sponsor":"Owner":"Crew
Chief":"Car Make":"Mini Biography":"Team Name"
I couldn't tell, are you struggling with this part?
[snip]
An attribute is simply a key/value pair in the anonymous
hash that makes up your object.
The above sentence from the specification explains your problem.
package Nascar;
sub new{
my $obj = {};
"just a key/value pair in the anonymous hash..."
my $obj = { Title => 'Whatever' };
$obj => {Title} =""; #Is this initilizing the
attribute?
bless $obj;
}
I dont know why I am just not getting this stuff.
Please help me.
I hope that helps go forward again.  Good luck.
James
P.S.  Never any shame in asking the teacher for some one-on-one help.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Creating hash with multiple keys for an array

2004-08-08 Thread Gunnar Hjalmarsson
Edward Wijaya wrote:

my @AoH = (
 { values => ['AGCAG','AGCCG','AGCCGGGCG','AGCCAGGAG'] },
 { values => ['AGCGGAGCG','AGCCGAGGG','AGCGGAGGG'] },
);
for ( 0..$#AoH ) {
 $AoH[$_]->{ic} = compute_ic( @{ $AoH[$_]->{values} } );
}
print Dumper @AoH;
Thanks Gunnar,
I managed to construct the Array of Hashes (@AoH) - Glad I did
that! Now, I don't have the clue of how to sort these hashes,
according to IC value and No of elements.
What have you done to find out?
perldoc -f sort
perldoc -q "sort an array"
I think you also need to read up on data structures:
perldoc perldsc
This is one suggestion:
print "Sorted by ic value\n";
for my $hashref ( sort { $a->{ic} <=> $b->{ic} } @AoH ) {
print "$hashref->{ic}: @{ $hashref->{values} }\n";
}
print "\n";
print "Sorted by number of elements\n";
for my $hashref ( sort {
@{ $a->{values} } <=> @{ $b->{values} }
} @AoH ) {
print "$hashref->{ic}: @{ $hashref->{values} }\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Assignment for Perl Class- hurting my brain

2004-08-08 Thread William Paoli
Im not looking to cheat, just a push in the right
direction.

This is assignment has to do with objects, classes,
packages, classes.

There is a text file that is comma delimited that we
will have to get data from.

The methods and what they will do are all layed out
for us. I am stuck on creating the constrctor method,
becasue the instructor gives us this:




The field format of the file is structured like this: 
"Car Number":"Driver Name":"Sponsor":"Owner":"Crew
Chief":"Car Make":"Mini Biography":"Team Name" 



To accomplish this project you must create a class and
a Perl application to access the methods and data you
create in your class. 



Specifications for Class: 

Name: Nascar.pm 

Description:
A package for displaying and searching a Nascar
driver's information. 

Attributes: 
 ->Title - String title of our data (eg. Winston Cup
2002 Drivers). The constructor method would be a good
place to initialize/create this attribute. An
attribute is simply a key/value pair in the anonymous
hash that makes up your object. 

___

So to this I am very confused and I wrote for my code:

package Nascar;

sub new{
my $obj = {};

$obj => {Title} =""; #Is this initilizing the
attribute?

bless $obj;

}

I dont know why I am just not getting this stuff.
Please help me.





__
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

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