Re: Joining 2 strings
From: Eric Bohlman (ebohlman_at_omsdev.com)
Date: 08/11/04
- Next message: David Combs: "Re: join on space instead of comma"
- Previous message: Jürgen Exner: "Re: Validating email addresses"
- In reply to: Sim: "Re: Joining 2 strings"
- Next in thread: Joe Smith: "Re: Joining 2 strings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Aug 2004 05:26:39 GMT
selena_kid@yahoo.com (Sim) wrote in
news:82bbfd98.0408101451.69866dfa@posting.google.com:
> I managed to solve the problem! It is very similar to the solution Jue
> posted. Here's how it goes. I wish to thank everyone who has thought
> through this problem. My MSN is jjsimz@hotmail.com. I am a college
> Physics student, and if you have any physics question, I might be of a
> little help. =)
>
>
> #!/usr/bin/perl
> use strict;
You want 'use warnings;' here as well.
>
> open (FILE, 'sample.out') or die "could not open 'sample.out'!!! ";
> open (OUTPUTFILE, '>>output.out') or die "could not open
> 'output.out'!!! ";
Error messages for files should say *why* the file couldn't be opened;
stick a $! in both messages.
> while (<FILE>) {
> s/^\s*((.*\S)?)\s*$/$1/; #removes spaces before and after the
> string
The FAQ recommends doing this in two substitutions (neither of which
requires capturing) rather than one; it's usually faster.
> print (OUTPUTFILE $_, ' ');
> if ($. % 3 == 0) {print (OUTPUTFILE "\n")}
> }
> close FILE;
> close OUTPUTFILE;
- Next message: David Combs: "Re: join on space instead of comma"
- Previous message: Jürgen Exner: "Re: Validating email addresses"
- In reply to: Sim: "Re: Joining 2 strings"
- Next in thread: Joe Smith: "Re: Joining 2 strings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|