Re: translate a file

2012-02-17 Thread John W. Krahn
lina wrote: Hi, Hello, I have a file, cat try.xpm a 1 b 2 c 3 d 4 abbbcdddb I wish to use perl to translate the last line into the numerical value. #!/usr/bin/perl use warnings; use strict; open FILE, "; while () { print $_; } strangely it print me nothing out, Thanks

Re: translate a file

2012-02-17 Thread Shawn H Corey
On 12-02-17 12:49 PM, Leo Susanto wrote: On Fri, Feb 17, 2012 at 9:17 AM, lina wrote: Thanks, here why you use '<', not "<" http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators '<' is literal, no interpolation. "<" is literal with interpolation. in this particular case, there

Re: translate a file

2012-02-17 Thread Leo Susanto
On Fri, Feb 17, 2012 at 9:17 AM, lina wrote: > Thanks, here  why you use '<', not "<" http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators '<' is literal, no interpolation. "<" is literal with interpolation. in this particular case, there is no difference between '<' and "<". But,

Re: translate a file

2012-02-17 Thread Brandon McCaig
Please note that I have rearranged the order of quotes for sanity. I hope that nobody minds or feels that I am misrepresenting the authors.. On Fri, Feb 17, 2012 at 10:58:45AM -0600, Hal Wigoda wrote: > On Fri, Feb 17, 2012 at 9:32 AM, lina wrote: > > #!/usr/bin/perl > > > > use warnings; > > use

Re: translate a file

2012-02-17 Thread lina
On Sat, Feb 18, 2012 at 12:53 AM, Shawn H Corey wrote: > On 12-02-17 11:43 AM, lina wrote: >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> >> my $file = "try.xpm"; >> >> open my $fh, "<$file" or die "could not open $file: $!\n"; > > > Use the three argument open, please: > >    open my

Re: translate a file

2012-02-17 Thread lina
On Sat, Feb 18, 2012 at 12:53 AM, Shawn H Corey wrote: > On 12-02-17 11:43 AM, lina wrote: >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> >> my $file = "try.xpm"; >> >> open my $fh, "<$file" or die "could not open $file: $!\n"; > > > Use the three argument open, please: > >    open my

Re: translate a file

2012-02-17 Thread Hal Wigoda
I don't know if this will fix it, but line 6 is missing a closing >. On Fri, Feb 17, 2012 at 9:32 AM, lina wrote: > Hi, > > I have a file, > >  cat try.xpm > a 1 > b 2 > c 3 > d 4 > > abbbcdddb > > > I wish to use perl to translate the last line into the numerical value. > > #!/usr/bin/perl

Re: translate a file

2012-02-17 Thread lina
On Sat, Feb 18, 2012 at 12:33 AM, Jim Gibson wrote: > At 12:10 AM +0800 2/18/12, lina wrote: >> >> >> What's the $_ and $@ > > > They are built-in global variables. $_ is the default variable for many Perl > operations. $@ is the syntax error message from the last eval (why are you > asking about

Re: translate a file

2012-02-17 Thread Shawn H Corey
On 12-02-17 11:49 AM, lina wrote: open my $fh, '<', $file or die "could not open $file: $!\n"; Here why use $! ? $! is the OS error. If an OS error occurs, like an open error, it contains the related error message. See `perldoc perlvar` and search for /OS_ERROR/ -- Just my 0.0002 mill

Re: translate a file

2012-02-17 Thread Shawn H Corey
On 12-02-17 11:43 AM, lina wrote: #!/usr/bin/perl use warnings; use strict; my $file = "try.xpm"; open my $fh, "<$file" or die "could not open $file: $!\n"; Use the three argument open, please: open my $fh, '<', $file or die "could not open $file: $!\n"; while (my $xpm_file = my<$fh>)

Re: translate a file

2012-02-17 Thread lina
On Sat, Feb 18, 2012 at 12:25 AM, Shawn H Corey wrote: > On 12-02-17 10:32 AM, lina wrote: >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> >> open FILE, "> >> my @line =; >> >> while () { >>        print $_; >> } >> >> strangely it print me nothing out, > > > Try: > > > #!/usr/bin/perl

Re: translate a file

2012-02-17 Thread lina
On Sat, Feb 18, 2012 at 12:25 AM, Shawn H Corey wrote: > On 12-02-17 10:32 AM, lina wrote: >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> >> open FILE, "> >> my @line =; >> >> while () { >>        print $_; >> } >> >> strangely it print me nothing out, > > > Try: > > > #!/usr/bin/perl

Re: translate a file

2012-02-17 Thread Jim Gibson
At 12:10 AM +0800 2/18/12, lina wrote: What's the $_ and $@ They are built-in global variables. $_ is the default variable for many Perl operations. $@ is the syntax error message from the last eval (why are you asking about $@; it doesn't appear in your program?). I can guess about its

Re: translate a file

2012-02-17 Thread Shawn H Corey
On 12-02-17 10:32 AM, lina wrote: #!/usr/bin/perl use warnings; use strict; open FILE, "; while () { print $_; } strangely it print me nothing out, Try: #!/usr/bin/perl use warnings; use strict; # place the file name in a variable # so that it can be easier changed later my $file

Re: translate a file

2012-02-17 Thread lina
On Fri, Feb 17, 2012 at 11:49 PM, Rob Coops wrote: > > > On Fri, Feb 17, 2012 at 4:32 PM, lina wrote: >> >> Hi, >> >> I have a file, >> >>  cat try.xpm >> a 1 >> b 2 >> c 3 >> d 4 >> >> abbbcdddb >> >> >> I wish to use perl to translate the last line into the numerical value. >> >> #!/usr/bin

Re: translate a file

2012-02-17 Thread Rob Coops
On Fri, Feb 17, 2012 at 4:32 PM, lina wrote: > Hi, > > I have a file, > > cat try.xpm > a 1 > b 2 > c 3 > d 4 > > abbbcdddb > > > I wish to use perl to translate the last line into the numerical value. > > #!/usr/bin/perl > > use warnings; > use strict; > > open FILE, " > my @line = ; > > wh

translate a file

2012-02-17 Thread lina
Hi, I have a file, cat try.xpm a 1 b 2 c 3 d 4 abbbcdddb I wish to use perl to translate the last line into the numerical value. #!/usr/bin/perl use warnings; use strict; open FILE, "; while () { print $_; } strangely it print me nothing out, Thanks for any suggestions, Bes