Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-30-2001, 06:31 PM   #1
Registered: Jun 2001
Posts: 100

Rep: Reputation: 15
perl: stupid question alert!!:)

hi all!
I'm trying to write a short program that can edit out a file, remove all the junk in it, leaving only these lines:

mcm: suzana siti zaleha roslan

anybody has any idea how to do this? I dont expect a full code of course ;D..only a hint or two would do me...btw, i'm using redhat linux...THANKS!!

oh...and i've been having trouble writing to file...i've got an example code:

open(INFO,">file") || die "Cannot open file: $!\n";


but nothing happened to the!
Old 07-31-2001, 06:05 AM   #2
Senior Member
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
Try this
#!/usr/local/bin/perl -w

$inputFile = "someFile";
$outputFile = "someOtherFile";

#read the whole input file into an array, then close the file
open(INPUT, $inputFile) or die "Unable able to open $inputFile - sorry!\n";
@input = (<INPUT>);

#grep that array for the lines you want, store these in a new array,
#although you could grep into the same array if you wanted to save memory
@someArray = grep /suzana/, @input;

#open your output file
open(OUTPUT, "> $outputFile");

#print each line of the array to the file, there's bound to be a tidier
#way to do this but my brain doesn't work that well at the moment
foreach $entry (@someArray) {
  print OUTPUT $entry;

#close the file, otherwise you'll get strange results.

Old 08-01-2001, 10:54 PM   #3
Registered: Apr 2001
Location: Texas
Distribution: Mandrake 8.0, RedHat 7.1
Posts: 48

Rep: Reputation: 15
1: $file="/opt/util/keluar/stuff' ;
2: open(INFO,">$file") || die "Cannot open file: $!\n";

In line 1 the ' should have been a " to match the opening quotation mark.
In line 2 file should have a $ before it to show that it is a variable,
otherwise you are going to write/overwrite to a file named "file"
in your current working directory (CWD).

Should look like below:

1: $file="/opt/util/keluar/stuff" ;
2: open(INFO,">$file") || die "Cannot open file: $!\n";


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stupid, stupid question; I lost Klaptop. :( Surfrider Slackware 2 08-31-2005 09:12 PM
Stupid Dumb Stupid Question... drigz Linux - Software 3 09-23-2004 03:09 PM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM
alert: newbie! apache question mikeindo Linux - Software 5 06-08-2004 03:17 PM
help needed (stupid question alert) Lox Linux - Newbie 5 08-31-2003 01:13 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration