TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Software World > Programming

Program Writing Help - Perl

Programming

 
Reply
Thread Tools Display Modes
Unread 16-11-2013, 06:38 PM   #1
Junior Member (25+)
Thread Starter
 
Jayoc22's Avatar
 
Join Date: Jul 2012
Location: Ireland
Posts: 69
Thanks: 8
Thanked 13 Times in 12 Posts
Mood: Psychedelic
Rep Power: 69 Jayoc22 is on a distinguished road

Intel Nvidia

Windows XP


Question Program Writing Help - Perl

Hi All,

I have a query. I am currently writing a program on Perl to generate usernames that can be used for my college.

for example:
Computer Class, Thompson, Tim
This should become: com.timt

I have this part sorted out but i want to find out how to take away double barrel names. For Example
Computer, Edwards-Graham, Ella-Mai
This should be
com.ellamaieg

Here is the code. (I have a load of it done so be patient)
Code:
#!/usr/bin/perl 
use Getopt::Std; 
use strict; 
#DATE: 10/2013 
#AUTHOR: Jason
my (%params,$params,$fileName,@data,$line,$class,$fname,$lname,$user,$first,$last,$string); 
getopts("hsnm:i: o:",\%params); 
if ($params{i} ne "") { 

$fileName=$params{i}; 
} 

if ($params{h}) { 
print "This is a help message about the usage of syntax\n"; 
} 
if ($params{o}) { 
print "STDOUT"; 
} 
if ($params{s}) { 
print "This is standard output\n"; 
} 
if ($params{m}) { 
print " mkuser -m 'adduser' -c _NAME_" ; 
} 
if ($params{n}) { 
print "No print\n"; 
} 
if ($params{t}) { 
print "Run Test mode\n"; 
} 
else { 

open FILE, "< $fileName"; 
@data=<FILE>; 
close FILE; 
foreach $line (@data) { 
 chomp $line; 
 ($class,$lname,$fname) = split ',', $line; 
 $fname=~s/^\s+//g; 
 $lname=~s/^\s+//g; 
 $user=$class; 
 $user=$user.'.'; 
 $user=$user.$fname; 
  #print "$class.$fname$lname\n"; 
  if ($lname =~ m/\s/) { 
   # if there's still a space, this is double barrel, 
   # get the bits either side of the ' ' 
   ($fname,$lname) = split /\s/, $fname; 
  ($lname) = ($lname) =~ /(^.{1})/; 
  ($lname, $fname) = split /\s\'/, $lname;   
  
  
   } 
  else { 
   ($first)= $lname =~ /(^.{1})/; 
    $user=$user.$first; 
    $user=lc $user; 
  
   } 

  
  
    #print "to console\n"; 
open OUTPUT, '>', "sampletxt.txt" or die "Can't create filehandle: $!"; 
select OUTPUT; $| = 1; #make unbuffered 
print "to file\n"; 
# close current output file 
close(OUTPUT); 
# reset stdout to be default file handle 
select STDOUT; 
 #print "user\n"; 
  use Term::ANSIColor qw(:constants); 
  print RED, "$user\n", RESET; 
  #print GREEN, "$user\n", RESET 

} 

} 

print "$user\n"
Please help.
Thank you in advanced

Sponsored Links
__________________
----- Help is only a Click Away -----

---------- ----------

----- Hit Thanks if I have Helped you -----

Last edited by Strider; 20-11-2013 at 08:24 PM..
Jayoc22 is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Program Language Jayoc22 General Q&A 0 12-10-2013 05:25 PM
writing a program in Notepad and running it using Internet Explore Angela Internet Explorer 1 19-02-2008 03:20 PM
Perl Conversion chris.santry@gmail.com VB.NET 1 15-09-2007 05:05 AM
ClearQuest API for PERL and VB and NOT FOR C#? RocketMan C#(C Sharp) 1 05-09-2007 09:09 AM
Perl Script Unknown Programming 0 16-12-2006 09:07 PM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 02:09 AM.


vBulletin, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © 2005-2016, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional