home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

need perl help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1622
Discussions: 200,509, Posts: 2,374,406, Members: 245,832
Old March 4th, 2003, 03:19 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2003
Posts: 10
need perl help

Hi, I'm new to this message board, and I suck at perl, so if anybody could help, it would be much appreciated.
OK, here's my problem.

I have a list of data in an input file that looks like this:
iep184:30201:222::/showme4/iep184:/usr/lbin/tcsh

The first portion, the iep184 part, is the user ID. I need to go through the list and get all user IDs that start with 'c' and end with '1'.

Any ideas? I think I have to use a split of some sort, but I'm not really sure how that works. Thanks for any help.
thelactator is offline   Reply With Quote
Old March 4th, 2003, 04:31 PM     #2 (permalink)
may contain mild peril
 
SpookyEddy's Avatar
 
Join Date: Oct 2001
Location: UK
Posts: 3,329
Sounds like you have the general idea, you could just split the line around : and then check the first field against a simple regexp to see if it matches you criteria. I can hack together some super ugly code for you when I get home if you want, but be warned that I also suck at Perl

Regards

eddy
__________________
I dreamt that a large eagle circled the room three times and then got into bed with me and took all the blankets.
SpookyEddy is offline   Reply With Quote
Old March 4th, 2003, 05:58 PM     #3 (permalink)
may contain mild peril
 
SpookyEddy's Avatar
 
Join Date: Oct 2001
Location: UK
Posts: 3,329
Ok first quick attempt that seems to basically work, but I could be horribly wrong (so please test on a non important file).
Code:
#!/usr/bin/perl -w
 
#### DISCLAIMER ###############
#
# Standard warnings, blah blah
# This code was written by a man with the IQ of a punch drunk monkey.
# I accept no responsibility for loss of data, life or sanity.
# 
###############################

use strict;

my $usage = <<EOT;
Usage: $0 [filename]
EOT

#do some rather shody checking on no. of args
if (@ARGV != 1) { die $usage }
my $file = shift;

#open an input file
open(FILE, $file) or die "Can't open input: $!";

#step over each line in the file
while(<FILE>){ 
        #split line up into an array
	my @line= split(/:/, $_);
        #print first element of array if it matches regexp
	if($line[0] =~ /^c(.*)1$/){ print "$line[0]\n" }
}

#Tidy up after reading
close(FILE);

#### The madness ends here ####
I will spend a few minutes later cleaning it up a bit and hunting down any major bugs, but you get the general idea.

Regards

eddy

Last edited by SpookyEddy : March 4th, 2003 at 06:03 PM.
SpookyEddy is offline   Reply With Quote
Old March 4th, 2003, 06:11 PM     #4 (permalink)
Junior Member
 
Join Date: Mar 2003
Posts: 10
Damn....you kick ass man...I can't thank you enough. One question, what does EOT do? Thanks again.
thelactator is offline   Reply With Quote
Old March 4th, 2003, 06:16 PM     #5 (permalink)
may contain mild peril
 
SpookyEddy's Avatar
 
Join Date: Oct 2001
Location: UK
Posts: 3,329
It just lets me read all the info before the last EOT into the variable, handy for writing stuff like multi-line help info you want printing to STDOUT. This would work just as well.....
Code:
my $usage = "Usage: $0 [filename]"
Anyway, hope it works and you are more than welcome. Any problems just shout and I will see if I can fix it.

Later

eddy
SpookyEddy is offline   Reply With Quote
Old March 4th, 2003, 06:22 PM     #6 (permalink)
Junior Member
 
Join Date: Mar 2003
Posts: 10
kick ass and chew bubblegum...thanks again mon frere.
thelactator is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (1635)
FT HOOD attack: 7 killed 12 injured (67)
Review My Build (6)
HELP!!! What do you think of this s.. (16)
Looking for a graphic card that wil.. (30)
Assosiations (21496)
My 1st pc build (40)
PC Modern Warfare 2: it's much wors.. (12)
Aero in Vista (7)
core i7 extreme 975, nvidia 9400gt (9)
How to Ship a PC (16)
Building my first computer (13)
[F@H SPAM 11/1/09]New month . . . n.. (33)
slaving laptop drive (7)
Recent Discussions
Windows Experience Index is screwed u.. (3)
boot from CD-ROM in chipset via P4M80.. (0)
Review My Build (6)
windows 7 retail and rtm (1)
FAT32 to NTFS file system in Win2kpro (4)
Internet very slow since updating AVG.. (8)
Motherboards and my curse... (25)
HELP!!! What do you think of this sys.. (16)
New Processor, Monitor will not turn .. (2)
2009 Build (4)
My 1st pc build (40)
Freezing During Music/Movies (1)
ext. sound card laptop to stereo syst.. (2)
Remote Desktop via SSH and error mess.. (2)
Help and Support disappeared from my .. (0)
[F@H SPAM 11/1/09]New month . . . new.. (33)
Basic applications needed for "r.. (1)
core i7 extreme 975, nvidia 9400gt (9)
hard drive problem (2)
Win7 TrustedInstaller Permissions (2)
Speed up Win 7 boot time a bit (1)
Hard Drive test program (2)
wireless westell versalink model 327w (1)
New build 10 second reboot cycle! Won.. (3)
New Linksys Routers (2)


All times are GMT -4. The time now is 07:08 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28