Programming :: Perl - Use Of Uninitialized Value In Split?
Apr 14, 2011
I'm currently teaching myself perl. I'm trying to write a program that unscrambles words by comparing each element in the array. There is an input file where you type the words to be unscrambled and there is a word list file containing approximately 1300 words. After everything has been processed the program is supposed to paste those words to an output file.
Code:
#!/usr/local/bin/perl
#use strict; #always add this in the beginning of code.
#use warnings; #always add this in the beginning of code.
#open(INFILE, '<', 'sample.txt'); # For reading
#open(INFILE, '>', 'sample.txt'); # For writing
#open(INFILE, '>>', 'sample.txt'); # To append .....
I want to strip the process name from the hosts - i did it with the code below.
I have two questions - is there a more compact way to strip off the process names? usalso i want to get rid of the errors after extracting the hostname. It is complaing about $arry[1]. using my $arry[1] is not allowed. Assigning the slice to a value, as is 'my $sliced_arry = $arry[1]; print $sliced_arry , does not work either.
Code:
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 16 here i get what i want - just the host name, but still get those nasty errors. assigning a value to $1 does not work, and localizing $1 with 'my' is not allowed.
I have an array called @logons. How can I step thru the array and split the fields? This is what I have so far, but doesnt work. I got the feeling I the split statement syntax is incorrect.
Code:
print @logons; foreach my $logons(@logons){ ($userid, $ip) = split(',',$logons);
[code]....
Update: Appears the data in @logons has a column header from the mysql query which I used to populate it with. So that code which I was testing does indeed work.
How do I catch the output of split and redirect it to another directory?for example,if my working directory is 'Documents' and I split a file called text.one into 4 files of 100 lines each (xaa, xab, xac, xad), how would I get those split files to be written into 'Directory/subdirectory' instead of 'Directory'?And is it possible to rename those split files so that the split name is suffixed with the original file's name e.g instead of xaa, xab... can they be written as text.one.xaa, text.one.xab..?I've thought about using '>' to send the output to a new directory but it doesn't work; and I've thought about piping the results to another command but I don't know what that other command should be.
I have a file in which contains one line with a lot floating points.In the very first place and some times in the downstream, there are a few integers, surrounded by blank spaces.1 1.02-4 1.03-5 544 1.04-1 65 2.98-1 5.78-10 3.45-2 etc etc.I aim to split the file in more files each of them containing an integer and the following floatings until the next integer.
I need to grep a pattern which can be present in one line or could be split in 2 lines.Normal grep wont work in this case. Can anyone please help on this?There are 100's of files in which i need to search for this pattern so time is also a constrain.
If there's another way to improve a script that I have created, since I'm not an expert! It works, and it made what I wanted, but it took a while to do it... maybe it can be improved. Here's the background. I have one file, with 244000 lines, let's call it X. I needed to split it in 1000 files, each one of 244 lines. I also needed the files to have the .arp extension. So here is what I did:
Code: for i in {1..1000} do sed -n '1,244p;244q' X > $i.arp sed -i '1,244d;' X # in this way I deleted the copied lines each time done
I have a large text file with three columns. I'm trying to write a PERL script that splits the file up based on the value of the 3rd column. So every time the third column reads 0, a new file is created and all the data up until the next 0 is found is written to that new file. This should happen over and over until the initial file has been entirely split up.
So I've got a rather vast database, one of the columns is date in the following format: DD/MM/YY HH:MM:SS. This is starting to cause problems with a php page I'm writing which asks the user for a 'start date'. Would it be better for me to split the date column into date and say time? Or is there a way of using distinct and masking the times.
I have a clean install of Fedora 12 and trying to mount a second hard disk with data created under Fedora 8. Nautilus lists the hard disk and can see all the folders and files under Places > Computer. However, Nautilus only lists hte hard disk (/dev/sdc) but no partitions (e.g. sdc1, sdc2) under Filesystem. LVM shows Partition1, Partition2 and UnPartitioned space under /dev/sdc. LVM shows Partition2 as 'uninitialized Disk Entity /dev/sdc2'. If I try to 'Block Initialize' Partition2 (which is the largest listed partition), LVM warns all data in the partition will be erased. A partition with all the data is on the hard disk because Nautilus can see it but the partition is not listed under /dev/sdc so I can mount it.
When I run ddclient with an existing ddclient.cache file I get errors saying "uninitialized value" and the remote IP address does not get updated. This pretty much renders ddclient useless. If I delete the cache file then things work fine and the IP address *does* get updated (if need be). I happen to be running version 3.7.3 of ddclient but I've tried this with ddclient 3.8.0 and the result is exactly the same except that the line number in the error changes to line 2030.
Here's the code at that line number :
Code: if ($config{$host}{'login'} eq '') { warning("null login name specified for host %s.", $host); I'm running ubuntu ( 9.04 I think ) and using zoneedit.com for dynamic dns. Here's a transcript showing the problem. root@ruby:/var/cache/ddclient# ddclient
I just downloaded Tk-804.028 and try to install it (according to the README.linux) but I get:
> perl Makefile.PL /opt/ActivePerl-5.10/bin/perl-static is installed in /opt/ActivePerl-5.10/lib okay PPM for perl5.010001 Test Compiling config/perlrx.c Test Compiling config/pmop.c Test Compiling config/pregcomp2.c
I really would like Perl Qt4 bindings. The best I could find is this:[URL]The problem is that the sources would not compile, and the RPMs are for 32-bit machines.Is there really no such thing as good Perl Qt4 bindings?
I am a newbie on linux and just searching everything about perl scripting and modules nearly 3-4 days. I need a perl script but one of not easy to find on searching google. Okay now I need a perl script which create or recreate (edit) id3 tags (artist, comment, album, year, cover) of mp3 files stored on my linux centos server. I installed MP3::Tag version 1.13 pearl module to my server. I Searched tutorials about how to use it, finally I get through reading id3 tag of mp3 file but not achieve to modify it or create a new id3tag.
These are the details: I have a mp3 file called 1.mp3 this script will process that '1.mp3' file read its id3tag if there is one, than modify or create id3tag for it by my fix artist name for example: '1.mp3' files id3 tag details are like this Artist: Dj xx Year:2010 Title:yyyyy Comment:eerwer Cover: x.jpg
Now via this perl script which uses MP3::TAG I will change it's artist as YYY Title:ttt Comment:cool Cover:t.jpg these are gonna be my fixed values. I mean all '1.mp3' file will have same artist based on script value.
The reason of this script is I will share Dj podcasts on my server and Dj's would have upload their mp3's which has got different id3 tags and cover pics. etc. I want to create more organized podcasts of them by the way I would trigger this perl script via Cronjob.
As some of you know that I am new to this forum. I have another problem that I got stuck on. I have this file called "Fib.rbb" and my instructor told us to write an interpreter program by using Fib.rbb.
"You are to write an interpreter in Perl for Rongs Basic Basic (RBB) as explained in class. The BNF description for RBB and a test file called Fib.rbb are part of the RBB.zip file which is available in the Course Documents folder on blackboard. If you call your interpreter myIntp.pl, you would execute the program via perl myIntp.pl Fib.rbb
Im somewhat new at perl and was wondering if there was a way to run a perl script or tool made from perl, from a USB pen that would work both on Linux and on Windows?