Re: newbie to perl
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Fri, 05 Aug 2005 10:20:50 -0700
In article <3MyIe.70266$Ph4.2186225@xxxxxxxxxxxxxxxxxxxxxxx>, Billy
Sproket <sproketmoviesrule@xxxxxxxxxxxxxx> wrote:
> This may seem to be a bit complex for a newbie, but I'm looking for some
> ideas as to how to go about this.
>
> Here's my "pseudo code"
>
> Open a file
> read a line
> While not at EOF do
> {
>
> if the first token is the word LoadName
> write the line out
> go to the next line
> if the first token is the word Font
> change the token to be LoadFont
> endif
> write the line out
> else
> if the first token is the word PrintName
> write the line out
> go to the next line
> if the first token is the word Font
> change the token to be PrintFont
> endif
> write the line out
> else
> write the line out
> endif
> endif
> read a line
> }
>
> Thre's probably a really simple way to do this, but none of the examples
> I can find in any book (O'Reily etc) can't put the pieces together
> enough to tell me how to do what I need to do. Even if someone can
> point me to a resource where I can learn how to do this it would be
> better than me spinning my wheels for hours trying to figure it out on
> my own.
Something like this?:
#!/usr/local/bin/perl
#
use warnings;
use strict;
open(my $fh, '<', 'filename') or die("Can't open filename: $!");
while(<$fh>)
{
my @tokens = split;
if( $tokens[0] eq 'LoadName' ) {
print;
$_ = <$fh>;
s/^(\s*)Font/$1LoadFont/;
print;
}elsif( $tokens[0] eq 'PrintName' ) {
print;
$_ = <$fh>;
s/^(\s*)Font/$1PrintFont/;
print;
}else{
print;
}
}
This assumes that your 'tokens' are separated by whitespace.
FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
.
- References:
- newbie to perl
- From: Billy Sproket
- newbie to perl
- Prev by Date: Re: Multileval data structures, tie, and indirection
- Next by Date: text on the screen
- Previous by thread: newbie to perl
- Next by thread: Multileval data structures, tie, and indirection
- Index(es):
Relevant Pages
|
|