Using MPDF Centos 7 - centos7

Help!!!! I installed MPDF with composer in centos 7 in order to print an pdf but it shows me this error, there but if i use mpdf in localhost (xampp) works perfectly.
this is the log error
[Thu Sep 20 13:54:37.030998 2018]
[php7:error]
[pid 27057]
[client 190.85.133.241:60785]
PHP Fatal error: Uncaught Mpdf\\MpdfException: Temporary files directory
"/var/www/html/pitah/vendor/mpdf/mpdf/src/Config/../../tmp"
is not writable in /var/www/html/pitah/vendor/mpdf/mpdf/src/Cache.php:17
\nStack trace:\n#0 /var/www/html/pitah/vendor/mpdf/mpdf/src/Mpdf.php(983): Mpdf\\Cache->_construct('/var/www/html/p...')\n#1
/var/www/html/pitah/pdf.php(183): Mpdf\\Mpdf->_construct(Array)\n#2 {main}\n thrown in /var/www/html/pitah/vendor/mpdf/mpdf/src/Cache.php on line 17,
referer: http://pitah.com.co/login/index.php
this is my mpdf config
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf(
'mode' => 'utf-8',
'format' => 'A4',
'orientation' => 'L',
'default_font' => 'mycustomfont',
'margin_left' => 15,
'margin_right' => 10,
'margin_top' => 16,
'margin_bottom' => 10,
'margin_header' => 10,
'margin_footer' => 10
]);
$mpdf->allow_charset_conversion=true;
$mpdf->charset_in='UTF-8';

already fixed, It was problem with SElinux, I used this: https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

Related

scandir(/var/app/current/protected/modules): Failed to open directory: No such file or directory

I have tried to host humhub which is an yii2 open source social media on aws elastic beanstalk but when I open the site I get an error exception
Can anyone tell me how to fix it please?
This is the error
PHP Warning – yii\base\ErrorException
scandir(/var/app/current/protected/modules): Failed to open directory: No such file or directory
in /var/app/current/protected/humhub/components/bootstrap/ModuleAutoLoader.php at line 50
yii\base\ErrorHandler::handleError(2, 'scandir(/var/app/current/protect...', '/var/app/current/protected/humhu...', 50)
in /var/app/current/protected/humhub/components/bootstrap/ModuleAutoLoader.php at line 50 – scandir('/var/app/current/protected/modul...')
in /var/app/current/protected/humhub/components/bootstrap/ModuleAutoLoader.php at line 32 – humhub\components\bootstrap\ModuleAutoLoader::locateModules()
in /var/app/current/protected/vendor/yiisoft/yii2/base/Application.php at line 327 – humhub\components\bootstrap\ModuleAutoLoader::bootstrap(humhub\components\Application)
in /var/app/current/protected/vendor/yiisoft/yii2/web/Application.php at line 69 – yii\base\Application::bootstrap()
in /var/app/current/protected/humhub/components/Application.php at line 46 – yii\web\Application::bootstrap()
in /var/app/current/protected/vendor/yiisoft/yii2/base/Application.php at line 273 – humhub\components\Application::bootstrap()
in /var/app/current/protected/vendor/yiisoft/yii2/base/BaseObject.php at line 109 – yii\base\Application::init()
in /var/app/current/protected/vendor/yiisoft/yii2/base/Application.php at line 206 – yii\base\BaseObject::__construct(['name' => 'HumHub', 'version' => '1.5.1', 'bootstrap' => ['log', 'humhub\components\bootstrap\Modu...', 'queue', 'humhub\modules\ui\view\bootstrap...', ...], 'sourceLanguage' => 'en', ...])
in /var/app/current/index.php at line 25 – yii\base\Application::__construct(['name' => 'HumHub', 'version' => '1.5.1', 'bootstrap' => ['log', 'humhub\components\bootstrap\Modu...', 'queue', 'humhub\modules\ui\view\bootstrap...', ...], 'sourceLanguage' => 'en', ...])

APEX 19.2 : Command line utility APEXExport throws error

I am trying to export my application using the command line utility APEXExport. (APEX 19.2)
Exception in thread "main" java.sql.SQLException: ORA-06550: line 2, column 12:
PLS-00306: wrong number or types of arguments in call to 'GET_APPLICATION'
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1054)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:612)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:223)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:56)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:907)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1119)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3780)
at oracle.jdbc.driver.T4CCallableStatement.executeInternal(T4CCallableStatement.java:1300)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3887)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4230)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1079)
at oracle.apex.APEXExport.exec_and_write_files(APEXExport.java:222)
at oracle.apex.APEXExport.ExportFile(APEXExport.java:523)
at oracle.apex.APEXExport.ExportFiles(APEXExport.java:332)
at oracle.apex.APEXExport.main(APEXExport.java:890)
Caused by: Error : 6550, Position : 17, Sql = begin
:1 := apex_export.get_application (
p_application_id => :2 ,
p_split => :3 ='Y',
p_with_date => :4 ='Y',
p_with_ir_public_reports => :5 ='Y',
p_with_ir_private_reports => :6 ='Y',
p_with_ir_notifications => :7 ='Y',
p_with_translations => :8 ='Y',
p_with_pkg_app_mapping => :9 ='Y',
p_with_original_ids => :10 ='Y',
p_with_no_subscriptions => :11 ='Y',
p_with_comments => :12 ='Y',
p_with_supporting_objects => :13 ,
p_with_acl_assignments => :14 ='Y',
p_components => apex_string.split(:15 ,'#') );
end;, OriginalSql = begin
? := apex_export.get_application (
p_application_id => ?,
p_split => ?='Y',
p_with_date => ?='Y',
p_with_ir_public_reports => ?='Y',
p_with_ir_private_reports => ?='Y',
p_with_ir_notifications => ?='Y',
p_with_translations => ?='Y',
p_with_pkg_app_mapping => ?='Y',
p_with_original_ids => ?='Y',
p_with_no_subscriptions => ?='Y',
p_with_comments => ?='Y',
p_with_supporting_objects => ?,
p_with_acl_assignments => ?='Y',
p_components => apex_string.split(?,'#') );
end;, Error Msg = ORA-06550: line 2, column 12:
PLS-00306: wrong number or types of arguments in call to 'GET_APPLICATION'
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:498)
... 18 more
I ran a fairly staright forward command from cmd
cd <Navigated to utilites folder in apex installation>
%JAVA_HOME%\java oracle.apex.APEXExport -db "myhost:myport:servicename" -user my_user -password my_password -applicationid 120
However, when i use APEX 18.2 installation, application is exported without issues.
Let me know if i am doing it wrong? Or is it a bug in APEX 19.2 (not listed in know issues)
Thanks in advance
Nowadays I would recommend using SQLcl instead of the "old" APEXExport utility...
SQLcl has built in APEX export tools which work nicely and have all the features of the old utility plus some more. Just connect with SQLcl to your DB parsing schema and type "apex export" for a command help page.
https://www.oracle.com/database/technologies/appdev/sqlcl.html
apex export command

AWS php sdk is not working with PHP 7

Following code works well in PHP 5.6.
require_once '../aws/aws-autoloader.php';
$config = [
'region' => 'ap-south-1',
'version' => 'latest',
'credentials' => [
'key' => '...',
'secret' => '...'
]
];
$sdk = new Aws\Sdk($config);
$client = $sdk->createS3();
But on PHP 7, it through error:
Fatal error: Uncaught TypeError: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must be an instance of Aws\Common\Credentials\CredentialsInterface, array given, called in /var/www/html/webservice/vendor/aws3/Aws/Sdk.php on line 316 and defined in /var/www/html/aws-sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php:75 Stack trace: #0 /var/www/html/webservice/vendor/aws3/Aws/Sdk.php(316): Aws\Common\Client\AbstractClient->__construct(Array) #1 /var/www/html/webservice/vendor/aws3/Aws/Sdk.php(291): Aws\Sdk->createClient('S3', Array) #2 index.php(14): Aws\Sdk->__call('createS3', Array) thrown in /var/www/html/aws-sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php on line 75
Please suggest me how can I make it work on PHP 7.
Thanks.
UPDATE: I have both AWS SDK version 2 & 3 in my project. this might be a issue of conflict. Then how to solve the conflict?
This problem doesn't have any issue with PHP 7.0.
It's the case of conflict SDK ver 2 & 3.
This two sdk can't be used together. so I had to upgrade to sdk 3.

How can I test Eloquent in Workbench?

EDITS: 1
I need to test an Eloquent model by touching the database and I Have this test case:
use Mockery as m;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Connectors\ConnectionFactory;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\ConnectionResolver;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Artisan;
use Illuminate\Container\Container;
use Illuminate\Config\Repository as Config;
use Illuminate\Database\Console\Migrations\MigrateCommand;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
use Illuminate\Filesystem\Filesystem;
class Module extends Eloquent {
protected $table = 'modules';
protected $fillable = array('name');
}
class UserTest extends PHPUnit_Framework_TestCase{
public function setUp()
{
$this->modelName = 'My Model Name';
$this->migrationsTable = 'migrations';
$this->environment = 'testing';
$this->connectionName = 'postgresql'; // postgresql memory
date_default_timezone_set('UTC');
$this->app = new Application;
$this->migrationPath = __DIR__ . '/../../migrations';
$this->app->instance('path', __DIR__);
$this->app->instance('config', $config = new Config(
$this->app->getConfigLoader(), $this->environment
));
$this->app['config']['app'] = array( 'debug' => true,
'url' => 'http://localhost',
'timezone' => 'UTC',
'locale' => 'en',
'key' => 'YourSecretKey!!!',
'providers' => array(
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
'Illuminate\Auth\AuthServiceProvider',
'Illuminate\Cache\CacheServiceProvider',
'Illuminate\Session\CommandsServiceProvider',
'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
'Illuminate\Routing\ControllerServiceProvider',
'Illuminate\Cookie\CookieServiceProvider',
'Illuminate\Database\DatabaseServiceProvider',
'Illuminate\Encryption\EncryptionServiceProvider',
'Illuminate\Filesystem\FilesystemServiceProvider',
'Illuminate\Hashing\HashServiceProvider',
'Illuminate\Html\HtmlServiceProvider',
'Illuminate\Log\LogServiceProvider',
'Illuminate\Mail\MailServiceProvider',
'Illuminate\Database\MigrationServiceProvider',
'Illuminate\Pagination\PaginationServiceProvider',
'Illuminate\Queue\QueueServiceProvider',
'Illuminate\Redis\RedisServiceProvider',
'Illuminate\Remote\RemoteServiceProvider',
'Illuminate\Auth\Reminders\ReminderServiceProvider',
'Illuminate\Database\SeedServiceProvider',
'Illuminate\Session\SessionServiceProvider',
'Illuminate\Translation\TranslationServiceProvider',
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
),
'manifest' => '/meta',
'aliases' => array(
'App' => 'Illuminate\Support\Facades\App',
'Artisan' => 'Illuminate\Support\Facades\Artisan',
'Auth' => 'Illuminate\Support\Facades\Auth',
'Blade' => 'Illuminate\Support\Facades\Blade',
'Cache' => 'Illuminate\Support\Facades\Cache',
'ClassLoader' => 'Illuminate\Support\ClassLoader',
'Config' => 'Illuminate\Support\Facades\Config',
'Controller' => 'Illuminate\Routing\Controller',
'Cookie' => 'Illuminate\Support\Facades\Cookie',
'Crypt' => 'Illuminate\Support\Facades\Crypt',
'DB' => 'Illuminate\Support\Facades\DB',
'Eloquent' => 'Illuminate\Database\Eloquent\Model',
'Event' => 'Illuminate\Support\Facades\Event',
'File' => 'Illuminate\Support\Facades\File',
'Form' => 'Illuminate\Support\Facades\Form',
'Hash' => 'Illuminate\Support\Facades\Hash',
'HTML' => 'Illuminate\Support\Facades\HTML',
'Input' => 'Illuminate\Support\Facades\Input',
'Lang' => 'Illuminate\Support\Facades\Lang',
'Log' => 'Illuminate\Support\Facades\Log',
'Mail' => 'Illuminate\Support\Facades\Mail',
'Paginator' => 'Illuminate\Support\Facades\Paginator',
'Password' => 'Illuminate\Support\Facades\Password',
'Queue' => 'Illuminate\Support\Facades\Queue',
'Redirect' => 'Illuminate\Support\Facades\Redirect',
'Redis' => 'Illuminate\Support\Facades\Redis',
'Request' => 'Illuminate\Support\Facades\Request',
'Response' => 'Illuminate\Support\Facades\Response',
'Route' => 'Illuminate\Support\Facades\Route',
'Schema' => 'Illuminate\Support\Facades\Schema',
'Seeder' => 'Illuminate\Database\Seeder',
'Session' => 'Illuminate\Support\Facades\Session',
'SSH' => 'Illuminate\Support\Facades\SSH',
'Str' => 'Illuminate\Support\Str',
'URL' => 'Illuminate\Support\Facades\URL',
'Validator' => 'Illuminate\Support\Facades\Validator',
'View' => 'Illuminate\Support\Facades\View',
),
);
$this->app['config']['database'] = array('connections' => array(
'memory' => array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
),
'postgresql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'antoniocarlosribeiro',
'username' => 'antoniocarlos',
'password' => 'basswort',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
)
);
$this->factory = new ConnectionFactory($this->app);
$this->manager = new DatabaseManager($this->app, $this->factory);
$this->migrateCommand = new MigrateCommand(
new Migrator(
new DatabaseMigrationRepository(
$this->manager,
$this->migrationsTable
),
$this->manager,
new Filesystem
),
$this->migrationPath
);
$this->model = new Module;
$this->model->setConnectionResolver($this->manager);
$this->model->setConnection($this->connectionName);
// $this->app->instance('artisan', $artisan = new Artisan($this->app));
// $this->app['artisan']->add($this->migrateCommand);
// $this->app['artisan']->call('migrate:refresh');
}
public function tearDown()
{
m::close();
}
public function testCreated()
{
$this->assertInstanceOf('Illuminate\Database\Eloquent\Model', $this->model);
}
public function testDeleteCreateSelect()
{
$this->model->on($this->connectionName)->where('name', $this->modelName)->delete();
$this->model->on($this->connectionName)->insert( array('name' => $this->modelName, 'created_at' => new DateTime, 'updated_at' => new DateTime) );
$this->assertEquals($this->model->where('name', $this->modelName)->first()->name, $this->modelName);
}
}
This thing is working fine. Delete, insert and select are working and hitting the database, so I get a green.
I plan to develop the tests on database, to take a look at the data and then move to :memory:, for speed.
The problem now is that I need Artisan to be working, so I can migrate:refresh on every run, but if I enable those 3 artisan lines it goes down to a recursive call to artisan:
PHP 1. {main}() /usr/share/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/share/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:63
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
PHP 5. PHPUnit_Framework_TestSuite->run() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349
PHP 6. PHPUnit_Framework_TestSuite->run() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705
PHP 7. PHPUnit_Framework_TestSuite->runTest() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP 8. PHPUnit_Framework_TestCase->run() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP 9. PHPUnit_Framework_TestResult->run() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:783
PHP 10. PHPUnit_Framework_TestCase->runBare() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
PHP 11. UserTest->setUp() /usr/share/phpunit/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:835
PHP 12. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/tests/Package/UserTest.php:174
PHP 13. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/tests/Package/UserTest.php:174
PHP 14. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 15. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 16. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:0
PHP 17. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 18. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 19. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:0
PHP 20. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 21. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 22. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:0
PHP 23. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 24. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 25. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:0
PHP 26. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 27. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 28. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:0
PHP 29. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 30. Illuminate\Foundation\Artisan->add() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
PHP 31. Illuminate\Foundation\Artisan->__call() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:0
PHP 32. call_user_func_array() /dev.app/workbench/antonio/package/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:82
Any leads on instantiating and using Artisan correctly?
Mocking a connection
Mocking a database connection gets complicated (I've done it before, it's messy!).
This is some code I had working in a unit test after a ton of trial and error some months ago:
Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface'));
$resolver->shouldReceive('connection')->andReturn($mockConnection = m::mock('Illuminate\Database\ConnectionInterface'));
$mockConnection->shouldreceive('getPostProcessor')->andReturn(m::mock('Illuminate\Database\Query\Processors\Processor'));
$mockConnection->shouldReceive('getQueryGrammar')->andReturn($queryGrammar = m::mock('Illuminate\Database\Query\Grammars\Grammar'));
$queryGrammar->shouldReceive('getDateFormat')->andReturn('Y-m-d H:i:s');
Using sqllite
I will suggest, then, to actually use a sqlite database for testing database connections. I've found this much easier.
Testing with PHPunit triggers the testing environment in Laravel, so you can define an in-memory (only on for that request) sqlite database connection on that environment and and even seed it in your test setup.
Here's a sample gist for testing using an in-memory sqlite database.
Testing things already tested
Your unit test here might be simplistic for example, I'm not sure - However, you're testing something that's already tested in Laravel. Consider carefully what you decide to test :D

help printing out hash keys to needed format

I need help printing out data from a hash/hash ref to STDOUT or file with
data in a specific order if possible.
I have a perl routine that uses hash references like so:
#!/usr/local/bin/perl
use strict;
use warnings;
use File::Basename;
use Data::Dumper;
my %MyItems;
my $ARGV ="/var/logdir/server1.log";
my $mon = 'Aug';
my $day = '06';
my $year = '2010';
while (my $line = <>)
{
chomp $line;
if ($line =~ m/(.* $mon $day) \d{2}:\d{2}:\d{2} $year: ([^:]+):backup:/)
{
my $server = basename $ARGV, '.log';
my $BckupDate="$1 $year";
my $BckupSet =$2;
$MyItems{$server}{$BckupSet}->{'MyLogdate'} = $BckupDate;
$MyItems{$server}{$BckupSet}->{'MyDataset'} = $BckupSet;
$MyItems{$server}{$BckupSet}->{'MyHost'} = $server;
if ($line =~ m/(ERROR|backup-size|backup-time|backup-status)[:=](.+)/)
{
my $BckupKey=$1;
my $BckupVal=$2;
$MyItems{$server}{$BckupSet}->{$BckupKey} = $BckupVal;
}
}
}
foreach( values %MyItems ) {
print "MyHost=>$_->{MyHost};MyLogdate=>$_->{MyLogdate};MyDataset=>$_->{MyDataset};'backup-time'=>$_->{'backup-time'};'backup-status'=>$_->{'backup-status'}\n";
}
Output using dumper:
$VAR1 = 'server1';
$VAR2 = {
'abc1.mil.mad' => {
'ERROR' => ' If you are sure is not running, please remove the file and restart ',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'MyDataset' => 'abc1.mil.mad'
},
'abc2.cfl.mil.mad' => {
'backup-size' => '187.24 GB',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'backup-status' => 'Backup succeeded',
'backup-time' => '01:54:27',
'MyDataset' => 'abc2.cfl.mil.mad'
},
'abc4.mad_lvm' => {
'backup-size' => '422.99 GB',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'backup-status' => 'Backup succeeded',
'backup-time' => '04:48:50',
'MyDataset' => 'abc4.mad_lvm'
}
};
Output formatted that I would like to see:
MyHost=>server1;MyLogdate=>Fri Aug 06 2010;MyDataset=>abc2.cfl.mil.mad;backup-time=>Fri Aug 06 2010;backup-status=>Backup succeeded
Just addded (8/7/2010):
Sample raw log file I am using: (recently added to provide better representation of the source log)
Fri Aug 06 00:00:05 2010: abc2.cfl.mil.mad:backup:INFO: backup-set=abc2.cfl.mil.mad
Fri Aug 06 00:00:05 2010: abc2.cfl.mil.mad:backup:INFO: backup-date=20100806000004
Fri Aug 06 00:48:54 2010: abc4.mad_lvm:backup:INFO: backup-size=422.99 GB
Fri Aug 06 00:48:54 2010: abc4.mad_lvm:backup:INFO: PHASE END: Calculating backup size & checksums
Fri Aug 06 00:48:54 2010: abc4.mad_lvm:backup:INFO: backup-time=04:48:50
Fri Aug 06 00:48:54 2010: abc4.mad_lvm:backup:INFO: backup-status=Backup succeeded
Fri Aug 06 00:48:54 2010: abc4.mad_lvm:backup:INFO: Backup succeeded
I've spent some time looking at your code and I think I have it figured out.
The reason this was hard to answer is that you've unintentionally planted a red herring--the data dumper output.
Notice how it shows $VAR1 = 'server1'; and then $VAR2 = { blah };.
You called Dumper like so: print Dumper %MyItems;
The problem is that Dumper wants a list of values to dump, since Perl flattens lists, complex structures must be passed by reference. So, you need to call Dumper like so:
print Dumper \%MyItems;
This shows the whole structure.
When you called dumper earlier, you inadvertently stripped off one layer of your data structure. The proposed solutions, and your own code are operating on this stripped structure.
Here I've bolted on some code to handle additional layer of nesting (and made it Perl 5.8 compatible):
for my $server_items ( values %MyItems ) {
for my $record ( values %$server_items ) {
print join ';', map {
# Replace non-existant values with 'undef'
my $val = exists $record->{$_} ? $record->{$_} : 'undef';
"'$_'=>$val" # <-- this is what we print for each field
} qw( MyHost MyLogdate MyDataset backup-time backup-status );
print "\n";
}
}
It looks like you have a lot of questions and need some help getting your head around a number of concepts. I suggest that you post a request on Perlmonks in Seekers of Perl Wisdom for help improving your code. SO is great for focussed question, but PM is more amenable to code rework.
** Original answer: **
To get around any parsing issues that I can't replicate, I just set %MyItems to the output of Dumper you provided.
Your warnings you mention above have to do with all the complicated quoting and repetitive coding you have in your print statement. I have replaced your print statement with a map to simplify the code.
Holy crap, a big join map blah is not simpler, you might be thinking. But really, it is simpler because each individual unit of expression is smaller. What is easier to understand and get right? What is easier to alter and maintain in a correct and consistent manor?
print "'foo'=>$_->{foo};'bar'=>$_->{bar};boo'=>$_->{boo};'far'=>$_->{far}\n";
or
say join ';', map {
"'$_'=>$item->{$_}"
} qw( foo bar boo far );
Here, you can add, remove or rearrange your output merely by changing the list of arguments passed to map. With the other style, you've got a bunch of copy/paste to do.
The map I use below is a bit more complex, in that it checks to see if a given key is defined before printing a value, and assign a default value if none is present.
#!perl
use strict;
use warnings;
use feature 'say';
my %MyItems = (
'abc1.mil.mad' => {
'ERROR' => ' If you are sure is not running, please remove the file and restart ',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'MyDataset' => 'abc1.mil.mad'
},
'abc2.cfl.mil.mad' => {
'backup-size' => '187.24 GB',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'backup-status' => 'Backup succeeded',
'backup-time' => '01:54:27',
'MyDataset' => 'abc2.cfl.mil.mad'
},
'abc3.mil.mad' => {
'backup-size' => '46.07 GB',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'backup-status' => 'Backup succeeded',
'backup-time' => '00:41:06',
'MyDataset' => 'abc3.mil.mad'
},
'abc4.mad_lvm' => {
'backup-size' => '422.99 GB',
'MyLogdate' => 'Fri Aug 06 2010',
'MyHost' => 'server1',
'backup-status' => 'Backup succeeded',
'backup-time' => '04:48:50',
'MyDataset' => 'abc4.mad_lvm'
}
);
for my $record ( values %MyItems ) {
say join ';', map {
my $val = $record->{$_} // 'undef'; # defined-or requires perl 5.10 or newer.
"'$_'=>$val" # <-- this is what we print for each field
} qw( MyHost MyLogdate MyDataset backup-time backup-status );
}
Not tested but it should work in theory. This will print an output line for each of the keys for the main MyItems hash. If you want it all on one line you can just drop the \n or add some other separator.
foreach( values %MyItems ) {
print "MyServer=>$_->{MyServer};MyLogdate=>$_->{MyLogdate};MyDataset=>$_->{MyDataset};backup-time=>$_->{backup-time};backup-status=>$_->{backup-status}\n";
}
Not answering the question you asked, but this doesn't seem sensible to me.
You want an array of hashes not a hash of hashes.
Hashes are not ordered, if you want them ordered then use an array.
Thanks everyone for pitching in their help...
This works for me.
for my $Server(keys%MyItems){
for my $BckupSet(keys%{$MyItems{$Server}}){
for(sort keys%{$MyItems{$Server}{$BckupSet}}){
print$_,'=>',$MyItems{$Server}{$BckupSet}{$_},';';
}
print"\n";
}
}