Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: opened file being overwritten

by Generoso (Parson)
on Dec 13, 2012 at 22:04 UTC ( #1008735=note: print w/ replies, xml ) Need Help??


in reply to opened file being overwritten

This is working fine for me.

#!/bin/Perl use warnings; if (@ARGV < 4) { print ("you need to provide 4 arguments\n\t4th argument is file to + parse"); exit; } openfile(@ARGV); sub openfile { print $_[3],"\n"; open FILE1,">$_[0]" || die "could not open $_[1]\n"; open FILE2,">$_[1]" || die "could not open $_[2]\n"; open FILE3,">$_[2]" || die "could not open $_[3]\n"; open FILE4,"<$_[3]" || die "could not open $_[4]\n"; while (<FILE4>) { print $_; } }

Result:

perl "E:\perl_TK\OpenFiles1.pl" a b c "e:\\territory20100713.sql" Process started >>> Name "main::FILE3" used only once: possible typo at E:\perl_TK\OpenFil +es1.pl line 16. Name "main::FILE1" used only once: possible typo at E:\perl_TK\OpenFil +es1.pl line 14. Name "main::FILE2" used only once: possible typo at E:\perl_TK\OpenFil +es1.pl line 15. e:\\territory20100713.sql -- MySQL dump 10.13 Distrib 5.1.37, for Win32 (ia32) -- -- Host: localhost Database: territory -- ------------------------------------------------------ -- Server version 5.1.37-community /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY +_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO +' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `address` -- DROP TABLE IF EXISTS `address`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `address` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Territory` varchar(45) NOT NULL, `Colonia` varchar(45) NOT NULL, `Street` varchar(60) NOT NULL, `Number` varchar(20) NOT NULL, `Lang` varchar(10) NOT NULL, `Notes` varchar(100) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=2302 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `address` -- LOCK TABLES `address` WRITE; /*!40000 ALTER TABLE `address` DISABLE KEYS */; INSERT INTO `address` VALUES (1,'','1- de Mayo','Av. 1- de Mayo','23 +9','Eng',''),(2,'','1- de /*!40000 ALTER TABLE `address1` ENABLE KEY +S */; UNLOCK TABLES; -- -- Table structure for table `streets` -- DROP TABLE IF EXISTS `streets`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `streets` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Territory` varchar(45) NOT NULL, `Colonia` varchar(45) NOT NULL, `Street` varchar(60) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=850 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `streets` -- LOCK TABLES `streets` WRITE; /*!40000 ALTER TABLE `streets` DISABLE KEYS */; /*!40000 ALTER TABLE `streets` ENABLE KEYS */; UNLOCK TABLES; -- -- Temporary table structure for view `territoy_list` -- DROP TABLE IF EXISTS `territoy_list`; /*!50001 DROP VIEW IF EXISTS `territoy_list`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `territoy_list` ( `Territory` varchar(45), `Colonia` varchar(45), `Street` varchar(60), `Number` varchar(20), `Name` varchar(100), `Notes` varchar(100), `Lang` varchar(10), `Pub` varchar(5), `S_ID` varchar(45) ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; -- -- Dumping routines for database 'territory' -- /*!50003 CREATE*/ /*!50020 DEFINER=`gene`@`%`*/ /*!50003 FUNCTION `act +uliza`(te CHAR(64), co CHAR -- Dump completed on 2010-07-13 16:17:07 <<< Process finished.


Comment on Re: opened file being overwritten
Select or Download Code
Re^2: opened file being overwritten
by Anonymous Monk on Dec 14, 2012 at 08:23 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2015-07-05 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls