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: 2707
Discussions: 200,965, Posts: 2,379,621, Members: 246,332
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
Forty-six years ago today (5)
Is It Just Me? (3006)
The disrespect of Obama by Russian .. (46)
Laptop with wireless problem. (11)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
Internet Lost (5)
windows 7 problem (7)
windows vista security holes (14)
Point and Shoot Camera Suggestions. (6)
Is the PSU I received dead? (13)
radeon x850xt platinum & shader.. (6)
Print spooler problem (16)
Recent Discussions
Laptop with wireless problem. (11)
Open With ..... Win7 (2)
Internet Lost (5)
Skillsoft Network+ Study Software Que.. (9)
NO GAS (0)
Help getting around port 80 for camer.. (3)
virus blocking exe. files (1)
windows vista security holes (14)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Nvidia GTX 260 problem (1)
Modern Warfare 2: Who Bought It? (65)
Is the PSU I received dead? (13)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
webcam (0)
upgrade for hp a6101 (0)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)


All times are GMT -4. The time now is 01:31 PM.
TechIMO Copyright 2009 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