lensman: (Default)
[personal profile] lensman
But I didn't....

Talked to B on the phone for a bit, and then got on the computer to bang my head against some windows cmd, and perl code.....

I thought I had it too, but it's been a few years since I played with perl and the perl side of the scripts are not doing what I want...

Anyone want to take a stab at this???

What I'm getting is a temp file where I need to find the following line:
      name: Last, First M

and what I want to have happen is that I get a stringthat would be:
$fullname="First M Last"


Should be simple right??? Thats the last piece to go, but I was banging my head on getting the rest of the dang scripts to work together until 7am this morning, and the a tried to catch some shut-eye before comming to work....



Here's what I tried:
open (USERINFO, "\\\\$userserver\\$userdirectory\\$username\\Settings\\Personal\\user-info.txt") || die "Open: $!";
#define variable fullname in case it is not found in the file.
#$fullname="";

while (defined ($temp = )) {
	chomp($temp);
	if ($temp =~ /^      name:\b/) { #Continue searching until a line starting with "      name:" is found
		$temp =~ s/      name:\s+//;
		$firstname=substr($temp,rindex $temp,", "); #$firstname includes MI
		$tempname=substr($temp,0,rindex $temp,", ");
		$lastname=substr($tempname,0,-2);
		$fullname=$firstname." ".$lastname;
	}
}

Am I missing something for the whitespace in frount of "name:"?
ext_4541: (Default)
From: [identity profile] happypete.livejournal.com
you're making this too hard on yourself...you've got way too many lines of code there...

undef $fullname;
#
while(!defined($fullname) && ($_ = )) #if we've already got a match or EOF, quit; else puts next line in $_
{
 if (/^.*name: (\w+), (\w+) (\w).*$/) # do we see a name sequence?
 {
  $fullname = "$2 $3 $1"; # put things in their proper order
 }
}
print "$fullname\n"; # just for grins

sample run:
$ perl lens.pl

junk
blah blah name: Thomas, Peter L
Peter L Thomas
$

crud...

Date: 2004-08-06 04:03 am (UTC)
ext_4541: (Default)
From: [identity profile] happypete.livejournal.com
I forgot to escape my brackets...

while(!defined($fullname) && ($_ = <STDIN>))

Re: crud...

Date: 2004-08-06 04:18 am (UTC)
ext_4429: (Default)
From: [identity profile] lensman.livejournal.com
You see thats one of both the beauties and headaches of perl....

There's a dozen ways to do everything and some of it just makes my head hurt...

Re: crud...

Date: 2004-08-06 09:13 pm (UTC)
ext_4541: (Default)
From: [identity profile] happypete.livejournal.com
oh the escaping the brackets thing was a problem with the formatting of my comment (the >STDIN< got eaten in comment #1)...

I thought this particular example of PERL use wasn't too painful...just took me a while to iterate to it.

Re: Another way to do it

Date: 2004-08-06 09:15 pm (UTC)
ext_4541: (Default)
From: [identity profile] happypete.livejournal.com
That won't eat the comma after the last name... and it also would treat all lines as having names even if they weren't preceded by "name:."

--Pete

Profile

lensman: (Default)
lensman

June 2012

S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 8th, 2026 01:26 pm
Powered by Dreamwidth Studios