Sponsored Content
Full Discussion: Shift Question (Perl)
Top Forums Shell Programming and Scripting Shift Question (Perl) Post 302274248 by otheus on Wednesday 7th of January 2009 05:22:35 AM
Old 01-07-2009
You are somehow trying to read the same file twice. This line reads the ENTIRE file into the @RawData array:
Code:
@RawData = <FILE>;

Then you try to start reading from files listed on the command line (or standard input) with
Code:
while (<>) {

1. Maybe you mean:
Code:
open(FILE, "test2.txt") or die("...");
while (<FILE>) { 
   # process one line in $_ at a time...
}

I think that's what you want.

2. To process: use split()
Code:
# inside while loop
($city,$year,$month,$day,$title,$speaker)=split('-'); 

# Convert month name to a number, or print existing value if not found in mapping.
$month=exists $month2int{$month} ? $month2int{$month} : $month;

# Canonicalize city name: use the value found in the map; if not in the map, just capitalize first letter. 
$city=exists $citymap{$city} ? $citymap{$city} : ucfirst($city);

# reconstruct and print out line.
print join("-",$city,$year,$month,$day,$title,$speaker);

3. Define your "mappings" for month names and cities. Do this before the while loop. Fill in the ellipses with the rest of the information you'll need....
Code:
%citymap = ( UC => "Union City", VJ => "Vallejo", ... );
%month2int  = ( Jan => 1, Feb => 2, ...., Jul => 7, July => 7, ... Okt => 10, Oct => 10, October => 10, ... );

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shift command

There is an error when i am trying to use the shift command in this way: ($1 = -d, $2 = 123, $3 = -c etc etc) for $arg in $@ do case $arg in "-d") shift; (so that the $2 will become the $arg now) (and while it loop the 2nd time,) ... (1 Reply)
Discussion started by: AkumaTay
1 Replies

2. Shell Programming and Scripting

shift command

Hi Folks, In shell scripting the maximum no. of command line parameters becomes 9(Am i right). If we want to get more than 9 parameters we use the shift command. Even here there are two possibilities. 1. Without the use of variables - The arguments are lost and the lost no. is equal to the... (6 Replies)
Discussion started by: Nisha
6 Replies

3. Shell Programming and Scripting

Regarding the shift command???

I am running a program where in I have this command which is giving error the shift: number is not correct. can you please tell me how shift actually works? the line which is giving error is- set $PARAM; shift; shift; shift; shift; shift; shift; shift; shift Is it related somewhere to... (2 Replies)
Discussion started by: shrao
2 Replies

4. Shell Programming and Scripting

shift and push question in perl

hi, another perl question, I don't understand the below while (<FILE>) { push @last5, $_; #add to the end shift @last5 if @last5 > 5 ; #take from the beginning } can someone please explain to me how does shift @last5 if @last5 > 5 is taking last 5 lines from... (5 Replies)
Discussion started by: hankooknara
5 Replies

5. UNIX for Dummies Questions & Answers

shift not working

Hi, I wrote one script, in between script needs to use 10th and 11th positional parameters, that time i used "shift". Here i am facing the below find problem, ./DataCount.sh: cannot shift I tried 1) I have read man pages for shift 2) Before but * and ** 3) Simple shift with out giving... (4 Replies)
Discussion started by: Nagapandi
4 Replies

6. Shell Programming and Scripting

script assistance with shift J

Hey all, I need some assistance. I'm writing a script to eject tapes from a tape library, but the library is not a queued system and can only eject 15 tapes at a time. I added paste -d : -s so that it goes through full_tapes and puts each media_id on one line separated by the :. Now I'm... (2 Replies)
Discussion started by: em23
2 Replies

7. UNIX for Dummies Questions & Answers

A Shift into UNIX

Hi, Firstly, I did a search for this question both on this site and on the internet and have not been able to find a suitable answer that is not general in nature. I have always been a Windows user. I use my girl friend's mac every now and then, but I always come back to windows. For a... (1 Reply)
Discussion started by: mearex
1 Replies

8. Shell Programming and Scripting

Use of Shift command

Hello Expert Can any one please explain what is the use of shift command in general terms: set -- $(ls -t) shift rm -Rf $* what is the use of shift command over here. Thanks a lot for your help (2 Replies)
Discussion started by: aks_1902
2 Replies

9. Homework & Coursework Questions

Need help with a Perl Script using Pop, Shift, & Push

Hello everyone, I am new to Perl and I am having some issues getting a script to work. I have to create a script that uses an array of 52 cards, "shuffles" the cards (using loops with the pop, shift, and push commands), and prints out the top five. This is not a randomizing of the array just a... (2 Replies)
Discussion started by: Hax0rc1ph3r
2 Replies

10. Shell Programming and Scripting

Shift command help

#!/bin/bash hostname=$1; shift for hostname in $1 do ping $hostname done I want to run the above script as hostname.sh yahoo.com google.com cnn.com. I want to shift each hostname to $1. How can do that with above code as currently it's not shifting. (5 Replies)
Discussion started by: scj2012
5 Replies
GEOIP_RECORD_BY_NAME(3) 						 1						   GEOIP_RECORD_BY_NAME(3)

geoip_record_by_name - Returns the detailed City information found in the GeoIP Database

SYNOPSIS
array geoip_record_by_name (string $hostname) DESCRIPTION
The geoip_record_by_name(3) function will return the record information corresponding to a hostname or an IP address. This function is available for both GeoLite City Edition and commercial GeoIP City Edition. A warning will be issued if the proper data- base cannot be located. The names of the different keys of the returning associative array are as follows: o "continent_code" -- Two letter continent code (as of version 1.0.4 with libgeoip 1.4.3 or newer) o "country_code" -- Two letter country code (see geoip_country_code_by_name(3)) o "country_code3" -- Three letter country code (see geoip_country_code3_by_name(3)) o "country_name" -- The country name (see geoip_country_name_by_name(3)) o "region" -- The region code (ex: CA for California) o "city" -- The city. o "postal_code" -- The Postal Code, FSA or Zip Code. o "latitude" -- The Latitude as signed double. o "longitude" -- The Longitude as signed double. o "dma_code" -- Designated Market Area code (USA and Canada only) o "area_code" -- The PSTN area code (ex: 212) PARAMETERS
o $hostname - The hostname or IP address whose record is to be looked-up. RETURN VALUES
Returns the associative array on success, or FALSE if the address cannot be found in the database. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 1.0.4 | | | | | | | Adding the continent_code with GeoIP Library | | | 1.4.3 or newer only | | | | | 1.0.3 | | | | | | | Adding country_code3 and country_name | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A geoip_record_by_name(3) example This will print the array containing the record of host example.com. <?php $record = geoip_record_by_name('www.example.com'); if ($record) { print_r($record); } ?> The above example will output: Array ( [continent_code] => NA [country_code] => US [country_code3] => USA [country_name] => United States [region] => CA [city] => Marina Del Rey [postal_code] => [latitude] => 33.9776992798 [longitude] => -118.435096741 [dma_code] => 803 [area_code] => 310 ) PHP Documentation Group GEOIP_RECORD_BY_NAME(3)
All times are GMT -4. The time now is 05:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy