Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

best way to handle pasted input that includes carriage returns 1

Status
Not open for further replies.

LaylaNahar

Programmer
Oct 25, 2006
26
US
Hello,

I want to build an array in perl by copying and pasting, as input, a list like the one below.

; MAC=0004f2125ad2
; MAC=0004f2125e5c
; MAC=0004f2125f15
; MAC=0004f212604a

The closest I have come is by using this code:

while(<STDIN>)
{
$newmac = <STDIN>;
push(@maclist, $newmac);
}

but it's buggy. I lose at least the first line pasted from the buffer. Sometimes I lose random lines from within the list if the copied buffer is long enough.

Can I paste a copied list that includes carriage returns and have a perl script parse what I paste without losing lines or data?

thank you
Layla

ps: My goal is to have to run one script and hit 'insert' only once - I'm open to any kind of solution that will allow that end.
 
Is this web based or CLI?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
CLI based (sorry - didn't think about that detail when posting!)
 
How long does the list have to be for it to have issues? I don't think I've ever run into issues taking input from STDIN.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
How are you copy and pasting data to STDIN to a cmdline script?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
To put it simply, I don't think that the paste buffer is going to be sufficient for needs if the dataset is too large. I suggest that you just copy into a text file and then run the script with the filename as a parameter.

- Miller
 
This just looks wrong too:

Code:
while(<STDIN>)
{
    $newmac = <STDIN>;
    push(@maclist, $newmac);
}

probably should be:

[/code]
while($newmac = <STDIN>)
{
push(@maclist, $newmac);
}
[/code]

otherwise it looks the first line of data will be lost since it is assigned to $_ in the opening condition. But for all I know there could be other problems, this is something rather unusual.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
crap, hit submit instead of preview.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you for the replies to my original post - I think i will probably go for the text file - I hope that I will get good enuf with the shell & scripting so that I can combine things so that people will be able to run 1 script, paste once and then the script will do its work -

thanks all for the feedback!
 
Or just slurp the whole lot rather than repeated calls to "push":
Code:
my @maclist = <STDIN>;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top