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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c&p in command line

Status
Not open for further replies.

nerri

Programmer
Sep 1, 2006
21
US
I am attempting to write a program the will take several line input and read it into an array.

print "\n\nPlease paste your data now.\n";
@data = <STDIN>;

However, at the command line I must press [CTRL-D] 3 times in order for the data to be read, and then have of the data is lost. I am on a Solaris 5.10 machine.
 

Can you have the program read the data from a file?
 
I can and do, but they want a copy and paste option as well.
 
That shouldn't be so hard with an edit box widget in Tk. Just paste into the edit box, and program a button to access the widget's contents.
 
I've never used widgets before; is there a tutorial you can point me at? I find that documents such as these are more useful once you are slightly familiar with what you are wanting to do.
 
I think this will be more trouble than is productive. Although it really looks cool, I can only find the the tk stuff as .tcl not .pm

The administrator is very busy and is not going to be able to help me with this and I can't download without root priveleges.

I may at some point download that to my laptop and fool around with it there, but in the meantime, can you help me at the original command line?
 
For the examples I used SunOS 5.9 Generic_118558-04 sun4u sparc SUNW,Sun-Fire-V440

Code:
print "\n\nPlease paste your data now.\n";
@foo = <STDIN>;
print "\n\nHere is what you inserted\n";
print foreach @foo;
if the last line of your input is blank then you need only one Ctrl+D. if the last line is not blank then you need to press enter and then Ctrl+D.
this way there is no loss of lines.
Code:
Please paste your data now.

MVPs
KevinADC
ishnid
Kirsle
raklet
PaulTEG
1DMF
rharsh
TonyGroves
stevexff
dmazzini
^D

Here is what you inserted

MVPs
KevinADC
ishnid
Kirsle
raklet
PaulTEG
1DMF
rharsh
TonyGroves
stevexff
dmazzini

of alternatively you can do something like
Code:
print "\n\nPlease paste your data now.\n";
while (($_ = <STDIN>) ne "0\n") {
    $foo .= $_;
}
print "\n\nHere is what you inserted\n";
print $foo,"\n";
so when you press a '0' and you hit enter it exits.
Like this
Code:
Please paste your data now.
MVPs
KevinADC
ishnid
Kirsle
raklet
PaulTEG
1DMF
rharsh
TonyGroves
stevexff
dmazzini
0


Here is what you inserted
MVPs
KevinADC
ishnid
Kirsle
raklet
PaulTEG
1DMF
rharsh
TonyGroves
stevexff
dmazzini


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Thank you...this has gotten me moving again. Where can I find some documentation on command line input? I have not seen this [ENTER], [CTRL-D] sequence.
 
This thing is still cutting off half of my data.

Code:
  print "\n\nPlease paste your information now.\n";
  @before_split = <STDIN>;
  print "\n\nHere is what you inserted\n";
  print foreach @before_split;
Code:
Please paste your information now.
 240 0420 0520 0610 0625  DSS-27  POLR   PB ONLY          5779  N083  H 1A1    
          STXL,SHMT,UPL,CCP,RNG,NMC,RRPA=2,TLPA=2                              
 240 0925 1005 1045 1055  DSS-66  POLR   PB ONLY          6022  NONE  A 3C1    
                                                                                
 240 1450 1530 1730 1740  DSS-46  POLR   PB OPS           5817  NONE  A 3C1    
                                                                                
 240 2310 2350 0050 0100  DSS66  POLR   PB ONLY          6023  NONE  A 3C1    
                              I'm                                                  
 241 0420 0500 0600 0610  DSS-46  POLR   PB ONLY          5818  NONE  A 3C1    
                                 not                                               
 241 0850 0930 1030 1040  DSS-46  POLR   PB ONLY          5818  NONE  A 3C1    
                                    here                                            
 241 1550 1630 1920 1930  DSS-46  POLR   PB OPS           5818  NONE  A 3C1    
                                        at all                                        
 241 2345 0045 0145 0200  DSS-34  POLR   PB ONLY          5819  N115  C 1A1    
          STXL,SHMT,UPL,CCP,RNG,NMC,RRPA,RRPB,TLPA,TLPB                        
 242 1000 1025 1250 1300  DSS-46  POLR   PB OPS           5819  NONE  B 3C1    
                                                                                
 242 1830 1910 2040 2050  DSS-46  POLR   PB OPS           5820  NONE  A 3C1    
                                                                                
 242 2300 2345 0020 0035  DSS-34  POLR   PB ONLY          5820  N130  D 1A1    
          STXL,SHMT,UPL,CCP,NMC,RRPA=2,TLPA,TLPB;                           
^D

Here is what you inserted
 241 2345 0045 0145 0200  DSS-34  POLR   PB ONLY          5819  N115  C 1A1    
          STXL,SHMT,UPL,CCP,RNG,NMC,RRPA,RRPB,TLPA,TLPB                        
 242 1000 1025 1250 1300  DSS-46  POLR   PB OPS           5819  NONE  B 3C1    
                                                                                
 242 1830 1910 2040 2050  DSS-46  POLR   PB OPS           5820  NONE  A 3C1    
                                                                                
 242 2300 2345 0020 0035  DSS-34  POLR   PB ONLY          5820  N130  D 1A1    
          STXL,SHMT,UPL,CCP,NMC,RRPA=2,TLPA,TLPB;

I have no idea where the rest of the data is going.
 
Here's something I've started looking into for my own scripts. You can use the clipboard to shuffle data between apps.


I've started toying with the idea of having a perl script continually monitor the clipboard for changes. Then when there is something there, capture the data to a variable, clear the clipboard again and process the captured data, over and over, in a continual loop.
Then again, you might just let the script know that it's time to access the clipboard directly.
 
nerri, what system and Perl are you using? Tk is already in the straight Active State installation, and it's likely in others as well. You might not need to install the module.
 
I looked for the TK module. It's not there. But everything is fixed now. I hope. I think. I think it was just cuz I was using Exceed. I had begun to suspect it was a buffer issue. I talked to a coworker and he said that the Exceed buffers are wonky anyways. The program worked when directly connected. Thank you all for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top